问题
Some of you might know why I get these errors, I am scripting in c++ at the moment and I can't figure out why I get these.
argument of type "const wchar_t *" is incompatible with parameter of type "LPCSTR"
argument of type "wchar_t *" is incompatible with parameter of type "LPSTR"
'int MessageBoxA(HWND,LPCSTR,LPCSTR,UINT)': cannot convert argument 2 from 'const wchar_t *' to 'LPCSTR'
'DWORD GetModuleFileNameA(HMODULE,LPSTR,DWORD)': cannot convert argument 2 from 'wchar_t [260]' to 'LPSTR'
I already tried disabling the character set, I tried using unicode and I tried using multi byte and I tried not set.
#include "stdafx.h"
XDebug Debug;
XPool Pool;
XMemory Memory;
XSilver Silver;
XFileIO File;
std::wstring wsErrorText = L"'Main' : Failed to load settings.";
Debug.m_fnAddError(wsErrorText, 1, true);
if (Debug.m_iErrorNumber > 999)
{
MessageBox(NULL, **Debug**.m_ecErrorChain[999].m_wsErrorText.c_str(), "Error", MB_OK);
}
else
{
MessageBox(NULL, Debug.m_ecErrorChain[**Debug**.m_iErrorNumber].m_wsErrorText.c_str(), "Error", MB_OK);
}
Debug.m_iErrorNumber++;
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}
wchar_t szFileName[MAX_PATH];
GetModuleFileName(NULL, **szFileName**, MAX_PATH);
std::wstring wsProcessName = szFileName;
wsProcessName = wsProcessName.substr(wsProcessName.find_last_of(L"\\") + 1);
if (wsProcessName == **Silver**.m_wXProcessName)
{
MessageBox(NULL, "Good job u fucked up.", "Dumbass", MB_OK);
exit(0);
}
while (Memory.m_iAttaching())
{
std::wstring wsErrorText = L"'Main': Failed to attach to process.";
Debug.m_fnAddError(wsErrorText, 2, true);
if (Debug.m_iErrorNumber > 999)
{
MessageBox(NULL, **Debug**.m_ecErrorChain[999].m_wsErrorText.c_str(), "Error", MB_OK);
}
else
{
MessageBox(NULL, Debug.m_ecErrorChain[**Debug**.m_iErrorNumber].m_wsErrorText.c_str(), "Error", MB_OK);
}
Debug.m_iErrorNumber++;
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}
XSilver::XDataTypes::XMilliTimer tmrTimer;
while (!Silver.m_bKillThread)
{
{
}
else if (iResult != 5)
{
Pool.m_fCurrentTime = 0.f;
}
if (iResult != 0 && iResult != 1 && iResult != 4 && iResult != 5 && iResult != 7 && iResult != 8 && iResult != 9 && iResult != 10 && iResult != 12 && iResult != 13 && iResult != 14 && iResult != 15 && iResult != 16 && iResult != 17)
{
std::wstring wsErrorText = L"'Main' : Failed to execute";
Debug.m_fnAddError(wsErrorText, 3, true);
if (Debug.m_iErrorNumber > 999)
{
MessageBox(NULL, **Debug**.m_ecErrorChain[999].m_wsErrorText.c_str(), "Error", MB_OK);
}
else
{
MessageBox(NULL, Debug.m_ecErrorChain[**Debug**.m_iErrorNumber].m_wsErrorText.c_str(), "Error", MB_OK);
}
Debug.m_iErrorNumber++;
}
tmrTimer.m_fnStopTimer();
if (tmrTimer.m_fGetCount() < Pool.m_setSettings.m_fThresholdSleepSkip)
{
std::this_thread::sleep_for(std::chrono::milliseconds((int)Pool.m_setSettings.m_fSleepTicks));
}
if (GetAsyncKeyState(VK_CONTROL) & 0x8000 && GetAsyncKeyState(VK_MENU) & 0x8000 && GetAsyncKeyState(VK_F1) & 0x8000)
{
Silver.m_bKillThread = true;
}
if (GetAsyncKeyState(VK_CONTROL) & 0x8000 && GetAsyncKeyState(VK_MENU) & 0x8000 && GetAsyncKeyState(VK_F2) & 0x8000)
{
while (File.m_iLoadedSettings())
{
std::wstring wsErrorText = L"'Main' : Failed to load settings.";
Debug.m_fnAddError(wsErrorText, 4, true);
if (Debug.m_iErrorNumber > 999)
{
MessageBox(NULL, **Debug**.m_ecErrorChain[999].m_wsErrorText.c_str(), L"Error", MB_OK);
}
else
{
MessageBox(NULL, **Debug**.m_ecErrorChain[Debug.m_iErrorNumber].m_wsErrorText.c_str(), L"Error", MB_OK);
}
Debug.m_iErrorNumber++;
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}
MessageBox(NULL, "Settings reloaded.", "Success", MB_OK);
}
}
if (Memory.m_iDetaching())
{
MessageBox(NULL, "Failed to detach. Terminating host process.", "Error", MB_OK);
exit(0);
}
MessageBox(NULL, "Sucessfully loaded", "Success", MB_OK);
return 0;
}
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
{
CreateThread(NULL, NULL, &Main, NULL, NULL, NULL);
}
}
return TRUE;
}
I have highlighted the errors, and deleted some code to prevent leechers. The words with ** between them are errors.
回答1:
You are using wchar_t
, so instead of macros like GetModuleFileName
and MessageBox
, you should use functions that explicitly use wide characters such as GetModuleFileNameW
and MessageBoxW
.
来源:https://stackoverflow.com/questions/37644147/vs2015-building-error-messagebox