你们中的一些人可能知道我为什么会遇到这些错误,我现在正在用c编写脚本,但我无法弄清楚为什么会得到这些错误 .
“const wchar_t *”类型的参数与“LPCSTR”类型的参数不兼容
“wchar_t *”类型的参数与“LPSTR”类型的参数不兼容
'int MessageBoxA(HWND,LPCSTR,LPCSTR,UINT)':无法将参数2从'const wchar_t *'转换为'LPCSTR'
'DWORD GetModuleFileNameA(HMODULE,LPSTR,DWORD)':无法将参数2从'wchar_t [260]'转换为'LPSTR'
我已经尝试禁用字符集,我尝试使用unicode,我尝试使用多字节,我尝试不设置 .
#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;
}
我已经突出显示了错误,并删除了一些代码以防止出现问题 . 它们之间带有**的单词是错误的 .
2 回答
您正在使用
wchar_t
,因此您应该使用明确使用宽字符的函数,例如GetModuleFileNameW
和MessageBoxW
,而不是像GetModuleFileName
和MessageBox
这样的宏 .现在我将名称更改为GetModuleFileNameW和MessageBoxW,它在其他文件中给了我更多错误 .