A
Asfar
I have a MFC dll in which one of the parameters is of LPSTR.
The declaration of my MFC dll looks like
extern "C" __declspec(dllexport) int WINAPI EXPORT TestPInvokeFunc(LPSTR
szFileName, LPSTR szResult[])
{
char resultchar[100];
//some processing which put the result values in resultchar
strcpy(szResult[0], &resultchar[0]);
return 0;
}
In VS2005 this function is declared as
[DllImport("PInvokeTest.dll")]
static int
TestPInvokeFunc([MarshalAsAttribute(UnmanagedType::LPStr)]String^,
[In][Out][MarshalAsAttribute(UnmanagedType::LPArray,
ArraySubType=UnmanagedType::LPStr, SizeConst=1)] array<String^>^);
This is how I call this function
int nFuncResult;
array<String^>^ strResult = gcnew array<String^>(1);
strResult[0] = ""
nFuncResult = TestPInvokeFunc(imgFileName, strResult)
I had to use string array because i want to return the modified value of
szResult to the calling function.
When doing the strcpy in TestPInvokeFunc I get an error that Heap block has
been modified past the requested size of 1.
Any ideas on what I might be doing wrong?
Thanks,
-Asfar
The declaration of my MFC dll looks like
extern "C" __declspec(dllexport) int WINAPI EXPORT TestPInvokeFunc(LPSTR
szFileName, LPSTR szResult[])
{
char resultchar[100];
//some processing which put the result values in resultchar
strcpy(szResult[0], &resultchar[0]);
return 0;
}
In VS2005 this function is declared as
[DllImport("PInvokeTest.dll")]
static int
TestPInvokeFunc([MarshalAsAttribute(UnmanagedType::LPStr)]String^,
[In][Out][MarshalAsAttribute(UnmanagedType::LPArray,
ArraySubType=UnmanagedType::LPStr, SizeConst=1)] array<String^>^);
This is how I call this function
int nFuncResult;
array<String^>^ strResult = gcnew array<String^>(1);
strResult[0] = ""
nFuncResult = TestPInvokeFunc(imgFileName, strResult)
I had to use string array because i want to return the modified value of
szResult to the calling function.
When doing the strcpy in TestPInvokeFunc I get an error that Heap block has
been modified past the requested size of 1.
Any ideas on what I might be doing wrong?
Thanks,
-Asfar