[英]no instance of overloaded function “strstr” matches the argument list
E0304 no instance of overloaded function "strstr" matches the argument list
嘗試編譯時出現此錯誤,我該如何解決? 發布代碼 cus 比照片更容易理解。 所以這是我得到的錯誤,我不知道是什么原因造成的以及如何解決。
int MakeWindows();
int CloseWindows();
int WINAPI WinMain(_In_HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow)
{
HW_PROFILE_INFO hwProfileInfo;
const char* cHWID = "{1234-5678-9669-1337}"; //
if (GetCurrentHwProfile(&hwProfileInfo) != NULL) }
printf("Hardware ID: %s\n", hwProfileInfo.szHwProfileGuid);
if (strstr(hwProfileInfo.szHwProfileGuid, cHWID)) {
printf("Your hardware ID was successful\n\n");
Sleep(3069);
system("CLS");
}
else {
printf("Your Hardware ID was denied;\n");
Sleep(1000);
TerminateProcess(GetCurrentProcess(), NULL);
}
}
else {
return 0;
}
};
strstr
想要一個char*
作為它的第一個參數。 szHwProfileGuid
將是一個寬字符串。 你需要wccstr
所以試試:
const wcchar* cHWID = L"{1234-5678-9669-1337}";
問題源於您的項目被編譯為 Unicode (“寬”字符,通常是wchar_t
類型或在 Windows 中定義為WCHAR
),並且您還使用單字節字符( char
或CHAR
),例如在調用strstr
() .
(正如你在這里看到的,兩者合作得並不好!)
Windows API 定義了其許多結構的兩個版本(以及使用它們的相應函數),一個用於適應每種字符類型。 在您的代碼示例中,對於 API 的寬字符版本, HW_PROFILE_INFO
實際上定義為HW_PROFILE_INFOW
,並且您正在調用GetCurrentHwProfileW
()。 這很好,而且是設計使然,因為您的構建被檢測為 Unicode 構建。
有幾種方法可以解決這個問題; 這是一個簡單的方法(您的原始代碼有兩個輕微的修改):
int MakeWindows();
int CloseWindows();
int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow)
{
HW_PROFILE_INFOA hwProfileInfo; // <== Change # 1
const char* cHWID = "{1234-5678-9669-1337}"; //
if (GetCurrentHwProfileA(&hwProfileInfo) != NULL) } // <== Change # 2
printf("Hardware ID: %s\n", hwProfileInfo.szHwProfileGuid);
if (strstr(hwProfileInfo.szHwProfileGuid, cHWID)) {
printf("Your hardware ID was successful\n\n");
Sleep(3069);
system("CLS");
}
else {
printf("Your Hardware ID was denied;\n");
Sleep(1000);
TerminateProcess(GetCurrentProcess(), NULL);
}
}
else {
return 0;
}
};
這組簡單的更改讓您明確使用 WINAPI 函數的單字節版本,保持您對strstr
()的調用與其兩個 arguments 一致。
(我會再次提到,這只是解決此問題的一種方法,“最佳”解決方案可能是主觀的。:))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.