peraonline
May 14th, 2004, 07:35 AM
I must get a string from a function included into a DLL, imported in a ASP.NET page.
The code:
----
Into a .aspx.cs page:
//def. function included into a DLL
[DllImport("WebUtility.dll", EntryPoint = "getDescr")]
public static extern string getDescr(int id);
//call the function:
string descr=getDescr(123);
---
into the c++ program, the function is definied as:
char* getDescr(int id) {
char* ret=new char[LUNGHEZZA_STRINGA_MEM];
strcpy(ret,oggetto[id].descr);
return (ret);
}
If I throw the application, the server give me the error: System.NullReferenceException: Object reference not set to an instance of an object.
But this error is generated not every time, but random!! some time I can view the string correctly! Why?
Thanks for the help!!!
The code:
----
Into a .aspx.cs page:
//def. function included into a DLL
[DllImport("WebUtility.dll", EntryPoint = "getDescr")]
public static extern string getDescr(int id);
//call the function:
string descr=getDescr(123);
---
into the c++ program, the function is definied as:
char* getDescr(int id) {
char* ret=new char[LUNGHEZZA_STRINGA_MEM];
strcpy(ret,oggetto[id].descr);
return (ret);
}
If I throw the application, the server give me the error: System.NullReferenceException: Object reference not set to an instance of an object.
But this error is generated not every time, but random!! some time I can view the string correctly! Why?
Thanks for the help!!!