Home > Software engineering > Dear brother, how static call from c DLL char * type returned by the function
Dear brother, how static call from c DLL char * type returned by the function
Time:11-10
Dear brother, a program in c + + call this function in c + + DLL
Extern "C" char * __stdcall GetSomething ()
{ Char * Name="WuHan"; Return the Name; } The code is as follows:
Char * vID=GetSomething ();
Results show that the DLL NAME value is normal, but returned to the c + + program is empty, where is the problem that how to solve? Thank you for your brother.
CodePudding user response:
GetSomething function change, GetSomething (cstrings STR);
CodePudding user response:
__stdcall to clean up the stack when the function exits, generally cannot use local variables to do return value
Try __cdecl
Or make a proposal to buffer and buffer and length as the pointer passed, it is not affected by calling code Extern "C" char * __stdcall GetSomething (char * szBuffer, int iLen) { Strcpy_s (szBuffer iLen, "XXXX"); Return szBuffer; }