converting from const char [] to 'LPWSTR'
-
When I compile this code in MSVC++ 2005 express I get the following error. SERVICE_TABLE_ENTRY DispatchTable[]= {{"Service1",serviceMain},{NULL,NULL}}; error C2440: 'initializing' : cannot convert from 'const char [9]' to 'LPWSTR' Pretty much where ever I am using a string I get the same error. Why doesn't the code work?
-
When I compile this code in MSVC++ 2005 express I get the following error. SERVICE_TABLE_ENTRY DispatchTable[]= {{"Service1",serviceMain},{NULL,NULL}}; error C2440: 'initializing' : cannot convert from 'const char [9]' to 'LPWSTR' Pretty much where ever I am using a string I get the same error. Why doesn't the code work?
I would have to see the definition of SERVICE_TABLE_ENTRY to be sure but I suspect it's defined to contain a wide character (UNICODE) string whereas "Service1" is a constant narrow character or (ASCII) string. UNICODE strings, usually, have 16bits per character while ASCII characters have only 8bits each so conversion between the two is non trivial. There's a whole world of pain involved here, code pages, locales, W2A macros, multi-byte character sets, UTF-8 and then some but what you need to do to make the above code work is make use of the _T() macro Microsoft so kindly supply.
SERVICE_TABLE_ENTRY DispatchTable[]= {{ **_T(** "Service1" **)** , serviceMain }, {NULL, NULL}};
Enjoy.Nothing is exactly what it seems but everything with seems can be unpicked.
-
When I compile this code in MSVC++ 2005 express I get the following error. SERVICE_TABLE_ENTRY DispatchTable[]= {{"Service1",serviceMain},{NULL,NULL}}; error C2440: 'initializing' : cannot convert from 'const char [9]' to 'LPWSTR' Pretty much where ever I am using a string I get the same error. Why doesn't the code work?