Is it possible to Dllimport a function returning an ArrayList

G

Guest

I get the following exception when it tries to run the GetWindowsAndDoors function in C

An unhandled exception of type 'System.Runtime.InteropServices.MarshalDirectiveException' occurred in WindowsApplication1.ex

Additional information: Can not marshal return value: The type definition of this type has no layout information

What is the correct way to do this. It's not like I have to marshall from one string type to another or anything. I get the sense that gc pointers to go through this mechanism. If this is the case, what would be a good way to handle this

Thanks

Inside of C+

extern "C

__declspec(dllexport) System::Collections::ArrayList* GetWindowsAndDoors(System::Int32 itemdefsClassID)


System::Collections::ArrayList* GetWindowsAndDoors(System::Int32 itemdefsClassID

System::Collections::ArrayList* al = new System::Collections::ArrayList()
// Do stuf
return al


Inside C

[DllImport("\\temp\\temp27\\output.dll")
public static extern System.Collections.ArrayList GetWindowsAndDoors(int itemdefsClassID)

... and Late

System.Collections.ArrayList al = GetWindowsAndDoors(1327)
 
M

Mattias Sjögren

Dave,
What is the correct way to do this.

Forget P/Invoke and the DllImport attribute. Make GetWindowsAndDoors a
method of a public __gc class and reference the C++ assembly from C#.



Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top