LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

ListType as parameter of a DLL-function from C#

I have a dll written in CVI, I should use the functions in C#. My problem is, that in some functions there is a list (ListType) as parameter.

 

CVI function definition:

int DLLEXPORT InserInList(ListType listSendRequest, char *cRequest)

Code in C#:

 

[DllImport("DLL_Test.dll", EntryPoint = "InsertInList", CallingConvention = CallingConvention.Cdecl)]
public static extern int InsertInList(List<RequestItem> listRequest, string Request);

[
DllImport("DLL_Test.dll", EntryPoint = "InsertInList", CallingConvention = CallingConvention.Cdecl)] public static extern int InsertInList(ArrayList listRequest, string Request);

I've tried two kinds of implementation in C#. With the first one an exception will be thrown, that generic types can not be marshaled. The second option runs at least without an error through, but the list in C# stays empty. Is there any chance to pass a list as a parameter to a dll-function?

 

Thanks.

0 Kudos
Message 1 of 2
(4,762 Views)

Hello Shaq,

 

You can't just pass .NET types like that. I guess what you're trying to do won't work. Your DLL has to create a new instance of the list which is then returned to the caller (your .NET application).

 

AFAIK the ListType is some sort of pointer to a hidden structure so you may just use IntPtr to store references to that list.

The PInvoke code should probably look like this:

[DllImport("DLL_Test.dll", EntryPoint = "InsertInList", CallingConvention = CallingConvention.Cdecl)]
public static extern int InsertInList(IntPtr listRequest, string Request);

 

Of course you need to retrieve a reference to an actual list object which is exported by your DLL.

ListType DLLEXPORT CreateList(void);

 

[DllImport("DLL_Test.dll", EntryPoint = "CreateList", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr CreateList();

 

Hope this helps.

 

regards,

kkeller

0 Kudos
Message 2 of 2
(4,698 Views)