problem with api call
hi
im busy porting an old c++ project to c# (console) and having some issues with an API call
the c++ api call is
char p_DllVersion( char* Version);
where the useage would be
char version[256];
p_DllVersion(&version);
printf("Version : %s",version);
but im not getting this right in c# i tried
[DllImport("c:\\p.dll")]
public static extern char p_DllVersion(ref String Version);
with useage
String version;
p_DllVersion(ref version);
printf("Version : %s",version);
but im getting error message
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
also tried to use out instead of ref and tried
public static extern char p_DllVersion([Out] String Version);
with no sucess ;(
please help
Daniel van PletzenPosted Jul 29, 2007, 5:04 AM
AlanPosted Jul 28, 2007, 6:31 AM
See if this will work:
using System.Text;
....
[DllImport("c:\\p.dll")]
public static extern char p_DllVersion(StringBuilder sbVersion);
and call with:
StringBuilder sbVersion = new StringBuilder(256);
p_DllVersion(sbVersion);
string version = sbVersion.ToString();
printf("Version : %s",version);