Hi,
I've been trying to make an exportable function return a string value. With not much success so far.
It is exporting just fine but what I'm getting back is a string full of rubbish. The program I'm calling the dll from is MapBasic basically a cutdown version of VB.
It says that the string to be returned must be as follows: You should store your string (not unicode) in a zero-terminated buffer and return a pointer to the buffer to MB.
As far as the function goes this is what I have:
At the moment I'm not sure what is non-unicode and how to send back the pointer.Code:LPTSTR __declspec(dllexport) __stdcall SayHello(BSTR BSTR_str) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CString CString_str = _T(""); if (BSTR_str != NULL) { CString s; LPSTR p = s.GetBuffer(::SysStringLen(BSTR_str) + 1); BOOL UsedDefaultChar; ::WideCharToMultiByte(CP_ACP, 0, BSTR_str, -1, p, ::SysStringLen(BSTR_str)+1, NULL, &UsedDefaultChar); if (UsedDefaultChar) { CString_str = (LPCTSTR)BSTR_str; } else { CString_str = (LPCWSTR)BSTR_str; } } AfxMessageBox(CString_str); CString_str = CString_str + " plus some text"; LPTSTR returnValue; returnValue = CString_str.GetBuffer(0); return returnValue; }
Any suggestions will be greatly appreciated!
Regards Hayden




Reply With Quote