Prev: tuple in variadic template class constructor initialization list
Next: Am I or Alexandrescu wrong about singletons?
From: column on 15 Mar 2010 08:00 { Please avoid compiler- and OS-specific issues in follow-ups. Thanks. -mod } Hello, I need to display int value in MessageBox in my dll that is created using MS C++ . Unfortunatedly I'm new in C++ and I don't know variable types like LPCWSTR and how to convert it from int. int i =10; MessageBox(NULL,TEXT(i),TEXT("hello"),MB_OK); Thank You -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Ulrich Eckhardt on 15 Mar 2010 19:44 column wrote: > I need to display int value in MessageBox in my dll that is created > using MS C++ . Unfortunatedly I'm new in C++ and I don't know > variable types like LPCWSTR and how to convert it from int. As the moderators already said, this is to system-specific and thus off topic. Better choices would be a dedicated win32/MS Windows programming group. Anyway... LPCWSTR is a macro or typedef of the win32 API. It means "Long Pointer to Const Wide-character STRing". The L part is obsolete, it came from times when there were different pointer types, you can basically forget about it. In the end, it is a pointer to a const wchar_t (wchar_t const*). > int i =10; > MessageBox(NULL,TEXT(i),TEXT("hello"),MB_OK); Note: TEXT() is a macro (you can often guess that from the ALL_UPPERCASE name, though not always in the win32 API, which also uses it for types). These macros are evaluated by the preprocessor, which is a mere text- replacement tool. That means that it also doesn't know about what an int is, let alone how to format it as a string. Further, win32-specific, this macro will turn a string literal either into a char-string literal or a wchar_t-string literal, depending on the compiler settings. What I would suggest is that you drop this macro and use wchar_t/WCHAR exclusively for the win32 API, because that is the native charset of contemporary MS Windows systems. In above example you would then drop the TEXT macros and append a W to the function: MessageBoxW(NULL, L"42", L"hello!", MB_OK); In order to convert an int to a string, there are lots and lots of ways, I guess the FAQ already covers a few. If not, please search the web. Take care that you will need a TCHAR string unless you convert to wchar_t/WCHAR! Uli -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: kevin zhang on 15 Mar 2010 19:45
On Mar 16, 7:00 am, column <column.col...(a)gmail.com> wrote: > { Please avoid compiler- and OS-specific issues in follow-ups. Thanks. -mod } > > Hello, > > I need to display int value in MessageBox in my dll that is created > using MS C++ . Unfortunatedly I'm new in C++ and I don't know > variable types like LPCWSTR and how to convert it from int. > > int i =10; > MessageBox(NULL,TEXT(i),TEXT("hello"),MB_OK); > > Thank You > > -- > [ Seehttp://www.gotw.ca/resources/clcm.htmfor info about ] > [ comp.lang.c++.moderated. First time posters: Do this! ] you can use swprintf("%d", i); or wstring str = i; str.c_str(); -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |