I am a programmer familiar with C# & Java and new to C . I am trying to create an editor in C# WPF for my C OpenGL application and I am following these tutorials: Creating OpenGL Windows in WPF and Walkthrough: Host a Win32 Control in WPF. The latter is from Microsoft.
This line of code Helper::ErrorExit(L"RegisterWindowClass");
gives me this error: Argument of type "const wchar_t*" is incompatible with parameter of type "LPTSTR"
. It is the L that is triggering this according to Visual Studio and I don't exactly know how to fix it.
public:
//
// Taken from MSDN
//
static void ErrorExit(LPTSTR lpszFunction)
{
// Retrieve the system error message for the last-error code
LPVOID lpMsgBuf;
LPVOID lpDisplayBuf;
DWORD dw = GetLastError();
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&lpMsgBuf,
0, NULL);
// Display the error message and exit the process
lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT,
(lstrlen((LPCTSTR)lpMsgBuf) lstrlen((LPCTSTR)lpszFunction) 40) * sizeof(TCHAR));
StringCchPrintf((LPTSTR)lpDisplayBuf,
LocalSize(lpDisplayBuf) / sizeof(TCHAR),
TEXT("%s failed with error %d: %s"),
lpszFunction, dw, lpMsgBuf);
::MessageBox(NULL, (LPCTSTR)lpDisplayBuf, TEXT("Error"), MB_OK);
LocalFree(lpMsgBuf);
LocalFree(lpDisplayBuf);
ExitProcess(dw);
}
CodePudding user response:
TEXT("RegisterWindowClass")
is supposed to be used.
Avoid using L"RegisterWindowClass"
or "RegisterWindowClass"
with parameters of type LPTSTR
.
Also change the parameter type to LPCTSTR in static void ErrorExit(LPCTSTR lpszFunction)
.