Hi all
C# code
///////////////////////////////////////////////////////////////////////////////////////
public delegate void EnumDateFormats ProcEx1([MarshalAs(Unman agedType.LPStr)]string xmlString);
[DllImport("demo dll.DLL")]
public static extern void GetContentsCall Back(ProcEx callBackProc);
GetContentsCall Back(Callback1) ;
public void Callback1(strin g xmlString)
{
Console.WriteLi ne(xmlString);
}
///////////////////////////////////////////////////////////////////////////////////////
C++ code
demo.h
extern "C" __declspec(dlle xport) void GetContentsCall Back(void *functocall);
demo.cpp
typedef void (*Myfunctocall) (char *xmlString);
Myfunctocall ptr;
char *y;
void GetContentsCall Back(void *functocall)
{
ptr = (Myfunctocall)f unctocall;
std::string resultString = "";
std::string r1 = "123123";
for(int i=0;i<20;i++)
{
resultString += "<fdsfds>"+r1+" </fdsfds>";
}
y = new char[resultString.le ngth() + 1];
for(int i = 0; i < resultString.le ngth(); i++)
y[i] = resultString[i];
ptr(y);
}
now this code works fine to the point where i get data i.e. this function "Callback1(stri ng xmlString)"
but as soon as debugger reaches at the end of this function program crashes
I have tried to run release version it crashes too and when i try to debug this program visual studio tells me this
"A buffer overrun has occurred in demotest.exe which has corrupted the program's internal state. Press Break to debug the program or Continue to terminate the program."
Now i have tried a null terminated string too but that doesnt seem to help
So i need help of expert people here
been 2 weeks and i have not been able to solve this problem even after looking at all the example on internet.
C# code
///////////////////////////////////////////////////////////////////////////////////////
public delegate void EnumDateFormats ProcEx1([MarshalAs(Unman agedType.LPStr)]string xmlString);
[DllImport("demo dll.DLL")]
public static extern void GetContentsCall Back(ProcEx callBackProc);
GetContentsCall Back(Callback1) ;
public void Callback1(strin g xmlString)
{
Console.WriteLi ne(xmlString);
}
///////////////////////////////////////////////////////////////////////////////////////
C++ code
demo.h
extern "C" __declspec(dlle xport) void GetContentsCall Back(void *functocall);
demo.cpp
typedef void (*Myfunctocall) (char *xmlString);
Myfunctocall ptr;
char *y;
void GetContentsCall Back(void *functocall)
{
ptr = (Myfunctocall)f unctocall;
std::string resultString = "";
std::string r1 = "123123";
for(int i=0;i<20;i++)
{
resultString += "<fdsfds>"+r1+" </fdsfds>";
}
y = new char[resultString.le ngth() + 1];
for(int i = 0; i < resultString.le ngth(); i++)
y[i] = resultString[i];
ptr(y);
}
now this code works fine to the point where i get data i.e. this function "Callback1(stri ng xmlString)"
but as soon as debugger reaches at the end of this function program crashes
I have tried to run release version it crashes too and when i try to debug this program visual studio tells me this
"A buffer overrun has occurred in demotest.exe which has corrupted the program's internal state. Press Break to debug the program or Continue to terminate the program."
Now i have tried a null terminated string too but that doesnt seem to help
So i need help of expert people here
been 2 weeks and i have not been able to solve this problem even after looking at all the example on internet.
Comment