Hi Jochen,
There is something more sinister going on.
strcpy(test,ca_LastConfigError());
strcpy(sOutput,test);
return;
single stepping through the above executes you can see that sOutput in the
locals windows has "Oracle error blah blah"
you can then single step to the return OK
when you single step again up into the VB Calling method you get an error
'An unhandled exception of type 'System.ExecutionEngineException' occurred
in Monitor.exe'
Seeing that the VB code and the VC++ code are both inside try catch blocks I
guess the error is somewhere in between the two.
if you can spot the problem I would be grateful.
Thanks
Bob
*********VB.net Calling code START************
Public Function LastConfigErrorMessage() As String
Try
Dim sb As New StringBuilder
sb.Capacity = 256 ' Desperation
sb.Length = 256 ' likewise
LastConfigError(sb)
Return sb.ToString
Catch ex As Exception
WriteErrorLog("DNP3Config.LastConfigErrorMessage " & ex.Message)
End Try
End Function
*************VB Code END************
*****VC++ code START***************
void DNPCONFIG_API LastConfigError(char *sOutput)
{
try
{
char test[255];
//strcpy(test, ca_LastConfigError());
//MessageBox(NULL,test,"",0);
strcpy(test,ca_LastConfigError());
//sOutput= ca_LastConfigError();
//MessageBox(NULL,test,"",0);
strcpy(sOutput,test);
//MessageBox(NULL,sOutput,"",0);
return;
}
catch (char * str)
{
char error[255];
strcpy(error,str);
MessageBox(NULL,error,"",0);
}
}
************VC++ CODE END******************
"Jochen Kalmbach [MVP]" <no********************@holzma.de> wrote in message
news:Of**************@TK2MSFTNGP15.phx.gbl...
Hi Bob!
I thought that if I passed in a stringbuilder by Ref from the VB code
the VC++ dll which is expecting a char* would point it at the returned char*
and all would be well.
void DNPCONFIG_API LastConfigError(char *sOutput)
{
sOutput="testing";
//strcpy(sOutput,test);
return;
}
You should be aware, that the pointer is "passed-into" your function!
With this code you change the pointer!
So please fill the string!
=> strcpy(sOutput, "Test");
and do *not* change the pointer of "sOutput"!
By the way:
It is a bad design to just pass an pointer to an string without passing
the maximum length of the buffer!
Please redesign your function prototype to:
void DNPCONFIG_API LastConfigError(char *sOutput, size_t nMaxLen)
--
Greetings
Jochen
My blog about Win32 and .NET
http://blog.kalmbachnet.de/