As Resmi Anna guessed, I suppose
Re
is a
CString
.
I am pretty sure the problem comes from string encoding: your are expecting your
CString
object to hold a string as
char*
array, but it is (in your project) a
wchar*
array (2 bytes per character).
There are 2 solutions to fix your issue:
1- Change your function declaration to make it accept wide chars:
extern "C" __declspec(dllexport) int ReturnSize(TCHAR* PortName)
{
PortName =Re;
return KbReceived;
}
But be carefull after to use wide character strings in the application that uses the dll.
2- If you want to force your
CString
to hold
char
, go to the
Project Properties page, in the
General tab, set
Character set to
Not set (and do it for both
Release and
Debug configurations).
I must now ask what you want to achieve with your function?
Because if you want to return a string object to the caller, you can't do it this way: the pointer your are setting will not be returned to the caller.
If you want to return the string just do something like that:
extern "C" __declspec(dllexport) LPCTSTR GetString()
{
return Re;
}