J
jacekbaz
I'm trying to use some closed source unmanaged C++ dll.
One of functions I have to call have signature as follows:
int getData(char * buffer, long * bufflen);
And this function requires that buffer is initialized to hold bufflen
chars.
bufflen after function is called will contain lenght of response
data.
If I try to marshall it using
[DllImport("mydll.dll",CharSet = CharSet.Ansi)]
public static extern int getData(
[MarshalAs(UnmanagedType.LPStr)] out StringBuilder result,
out long bufflen);
i get acces violation exception, despite that string builder is
initialized by:
long bufflen 256;
StringBuilder result = new StringBuilder((int)bufflen);
DllMapper.getData(out result, out bufflen);
What I'm doing wrong?
One of functions I have to call have signature as follows:
int getData(char * buffer, long * bufflen);
And this function requires that buffer is initialized to hold bufflen
chars.
bufflen after function is called will contain lenght of response
data.
If I try to marshall it using
[DllImport("mydll.dll",CharSet = CharSet.Ansi)]
public static extern int getData(
[MarshalAs(UnmanagedType.LPStr)] out StringBuilder result,
out long bufflen);
i get acces violation exception, despite that string builder is
initialized by:
long bufflen 256;
StringBuilder result = new StringBuilder((int)bufflen);
DllMapper.getData(out result, out bufflen);
What I'm doing wrong?