Hi, I'm pretty much new to windows programming.
I'm trying to write my own MessageBox function.So far I manage to do this:
When I compile it and run it everything works fine, but if I do this:Code:#include <windows.h> #include <stdio.h> #include <tchar.h> int __cdecl MyMessageBox (HWND hwnd,TCHAR * szCaption,UINT uType,const TCHAR * szFormat, ...) { TCHAR szBuffer[1024]; va_list pArgList; va_start(pArgList,szFormat); _vsntprintf(szBuffer,sizeof(szBuffer)/sizeof(TCHAR),szFormat,pArgList); return MessageBox(NULL,szBuffer,szCaption,0); } int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { int x=5; MyMessageBox(NULL,_T("Caption"),MB_OK,_T("%d"),x); return 0 ; }
I get compiler errors:Code:#define UNICODE #include <windows.h> #include <stdio.h> #include <tchar.h> int __cdecl MyMessageBox (HWND hwnd,TCHAR * szCaption,UINT uType,const TCHAR * szFormat, ...) { TCHAR szBuffer[1024]; va_list pArgList; va_start(pArgList,szFormat); _vsntprintf(szBuffer,sizeof(szBuffer)/sizeof(TCHAR),szFormat,pArgList); return MessageBox(NULL,szBuffer,szCaption,0); } int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { int x=5; MyMessageBox(NULL,_T("Caption"),MB_OK,_T("%d"),x); return 0 ; }
error C2664: '_vsnprintf' : cannot convert parameter 1 from 'TCHAR [1024]' to 'char *'
error C2664: 'MyMessageBox' : cannot convert parameter 2 from 'char [8]' to 'TCHAR *'
I manage to eliminate the second error by changing line:
to line:Code:MyMessageBox(NULL,_T("Caption"),MB_OK,_T("%d"),x);
This is not what I expected because I found in header files something like this:Code:MyMessageBox(NULL,TEXT("Caption"),MB_OK,TEXT("%d"),x);
I thought that _T and TEXT are equivalent, but it seems they aren't.Code:... #define _T(x) L##x //tchar.h ... #define _TEXT(quote) L##quote //winnt.h ... #define TEXT(quote) __TEXT(quote)
Anyway I was not be able to solve first error, so my program will not work if UNICODE is defined.
I tried to use preprocessor and to define _vsntprintf as
_vsnwprintf if UNICODE is defined, but failed.
So I have two question:
1. How to fix this errors so my program work with UNICODE defined
2. What is the difference between _T and TEXT.
I'm using .net and windows XP
Thank you very much!



LinkBack URL
About LinkBacks


