Using unmanaged dll in c#: how to marshal a struct

T

Thomas183

Hi,

I have a unmanaged c++ dll, and want to call a function
"dlltest(mystruct a)"of it.
The Parameter mystruct is a struct which consists of a array of
strings:

struct mystruct
{
char * myArray[100];
}

I searched the net for on hole day, to find a way to marshal this.
I have tried the following in C#:

[ StructLayout (LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct x_struct
{
[MarshalAs(UnmanagedType.LPArray, SizeConst=2)]

public [] string d;
};



[DllImport ("MyFile.dll", callingConvention.StdCall)]]
public static extern string dlltest(x_struct X);


The dll is in the system32 dir and functions with other structs (only
int) worked fine.

But with this one i get a EntryPointNotFound exception.

Thanks for your help

Thomas
mailto: (e-mail address removed)
 
G

Guest

Hi Thomas,

Try to change definition of your struct:
Hi,

I have a unmanaged c++ dll, and want to call a function
"dlltest(mystruct a)"of it.
The Parameter mystruct is a struct which consists of a array of
strings:

struct mystruct
{
char * myArray[100];
}

I searched the net for on hole day, to find a way to marshal this.
I have tried the following in C#:
[ StructLayout (LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct x_struct
{
//[MarshalAs(UnmanagedType.LPArray, SizeConst=2)]
//public [] string d;
public StringBuilder strBldr;

public x_struct(int size) {
strBldr=new StringBuilder(size);
}
};

I cannot assure you that it will work as a struct...
but i have used StringBuilder many times in replace
with "char*".

Excuse my english :)

Regards

Marcin
 

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