How to Access/marshall char *variable from dll import in C#
void GetGeneratedKey(char *code, int len, char *key)
pls help in this.
Thanks
nRkThis depends highly on what is happening to the variables key
and code
in the native C function. Based on the signature I am guessing that code
is being read from and key
is being written to. If that is the case then try the following signature
[DllImport("SomeDll")]
public static extern void GetGeneratedKey(
[In] string code,
[In] int length,
StringBuilder key);
Just use string
. Should just work.
everybody for the quick reply and support
I used method signature like the below
VC++ method signature
void GetGeneratedKey(char *code, int len, char *key)
C# signature
[DllImport("SomeDll")]
public static extern void GetGeneratedKey(byte[] code, int len, bute key);
nRk
Here is my solution for Unmanaged case.
C++
void GetGeneratedKey(
const char *code,
int length,
char *key);
C#
[DllImport("Some.Dll")]
public static extern void GetGeneratedKey(
[MarshalAs(UnmanagedType.LPStr)]string code,
int length,
[MarshalAs(UnmanagedType.LPStr)]StringBuilder key);
精彩评论