Hello everyone, I'm still working on my Win32 DLL in C++, hopefully I'm almost finished, but I have a little problem, I'll try to explain at my best:
I wrote a class, CSimpleWindow, which has, amongst the others, those methods:
int BuildWindow ( const wchar_t* strTitle, const wchar_t* strName, WNDPROC callback, int nCmdShow );
int BuildWindow ( const char* strTitle, const char* strName, WNDPROC callback, int nCmdShow );
The class is made to work only with unicode strings internally. Assuming that overload is the correct way to deal with Unicode/ANSI support, I wrote those two methods: the first one does all the real work, while the second one only converts the char* arguments into wchar_t* and passes them to the first one, like this:
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, strTitle, -1, strTitleW, (int)uTitle + 1);
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, strName, -1, strNameW, (int)uName + 1);
const int nRet = BuildWindow(strTitleW, strNameW, callback, nCmdShow);
Ok, now to the problem: from the exe that uses my dll, if I call the first method (thus, UNICODE is defined), all is well. If I don't define UNICODE, the overloaded method gets invoked, correctly converts the string and the wchar_t* version of BuildWindow() is called, BUT! the text of the newly created window is truncated, apparently to the first NULL char (char, although CreateWindowExW() is being called).
This is how the exe calls the CSimpleWindow's method:
wnd.BuildWindow(TEXT("Window"), TEXT("CWNDTEST"), &EventHandler, SW_SHOW);
The window's title is just a "W", as if the padding 0 was seen as a terminating null char. MessageBox(), on the other hand, displays the full string.
I added the following test code to the wchar_t version of BuildWindow():
unsigned char ch[] = {
0x44, 0x30, 0x57, 0x30, 0x83, 0x30, 0x26, 0x20, 0x01, 0xFF,
0x00, 0x30, 0x44, 0x30, 0x57, 0x30, 0x83, 0x30, 0x01, 0xFF,
0x00, 0x30, 0x42, 0x30, 0x42, 0x30, 0x01, 0xFF, 0x00, 0x30,
0x4A, 0x30, 0x8C, 0x30, 0x60, 0x30, 0x01, 0xFF, 0x00, 0x00
};
m_hWnd = CreateWindowEx (0, strClassSrc, (wchar_t*)&ch[0], dwWindowstyle, 0, 0, 640, 480, NULL, NULL, hAppInstance, NULL);
MessageBox(0, (wchar_t*)&ch[0], strClassSrc, MB_OK | MB_ICONSTOP);
Here, the title is only 5 characters long, as if the 0x3000 was a terminator. Again, MessageBox() works fine. The fun thing is that ch[] is hardcoded within the dll, but defining/undefining UNICODE within the exe (without recompiling the dll) messes up everything.
I imagine I could've explained all this much better, but I'm a bit tired, so sorry for the long post :/ I hope you guys get the point.