简体   繁体   English

没有重载 function “strstr”实例与参数列表匹配

[英]no instance of overloaded function “strstr” matches the argument list

E0304   no instance of overloaded function "strstr" matches the argument list

I'm getting this error when try to compile, how can i fix this?尝试编译时出现此错误,我该如何解决? post the code cus it's better to understand then photo.发布代码 cus 比照片更容易理解。 So this is the error that i'm getting i don't have any idea what is causing this and how to fix.所以这是我得到的错误,我不知道是什么原因造成的以及如何解决。

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 wants a char* as its first arg. strstr想要一个char*作为它的第一个参数。 szHwProfileGuid is going to be a wide string. szHwProfileGuid将是一个宽字符串。 You need wccstr你需要wccstr

So try:所以试试:

const wcchar* cHWID = L"{1234-5678-9669-1337}";

The problem stems from your project being compiled as Unicode ('wide' characters, usually wchar_t types or defined in Windows as WCHAR ), and you also using single-byte characters ( char or CHAR ), for example in your call to strstr () .问题源于您的项目被编译为 Unicode (“宽”字符,通常是wchar_t类型或在 Windows 中定义为WCHAR ),并且您还使用单字节字符( charCHAR ),例如在调用strstr () .

(As you're seeing here, the two don't cooperate nicely!) (正如你在这里看到的,两者合作得并不好!)

The Windows API defines two versions of many of its structures (and therefore the respective functions that use them), one to accommodate each character type. Windows API 定义了其许多结构的两个版本(以及使用它们的相应函数),一个用于适应每种字符类型。 In your code example, HW_PROFILE_INFO is actually defined as HW_PROFILE_INFOW for the wide-character version of the API, and you're invoking GetCurrentHwProfileW ().在您的代码示例中,对于 API 的宽字符版本, HW_PROFILE_INFO实际上定义为HW_PROFILE_INFOW ,并且您正在调用GetCurrentHwProfileW ()。 This is fine and by design, since your build is instrumented as a Unicode build.这很好,而且是设计使然,因为您的构建被检测为 Unicode 构建。

There are a few ways you could fix this;有几种方法可以解决这个问题; here's a simple method (your original code with two slight modifications):这是一个简单的方法(您的原始代码有两个轻微的修改):

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;
    }
};

This set of simple changes has you explicitly using the single-byte versions of the WINAPI functions, keeping your call to strstr () consistent for its two arguments.这组简单的更改让您明确使用 WINAPI 函数的单字节版本,保持您对strstr ()的调用与其两个 arguments 一致。

(I'll mention again that this is only one way to fix this problem, and the "best" solution may be subjective. :)) (我会再次提到,这只是解决此问题的一种方法,“最佳”解决方案可能是主观的。:))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 没有重载函数的实例“getline”匹配参数列表 - no instance of overloaded function “getline” matches argument list 没有重载函数的实例与参数列表匹配。 - No instance of overloaded function matches argument list. 没有重载函数“搜索”的实例与参数列表匹配 - no instance of overloaded function “search” matches the argument list 没有重载函数“stoi”的实例与参数列表匹配 - no instance of overloaded function "stoi" matches the argument list 没有重载 function AddSnapshotListener 的实例与参数列表匹配 - no instance of overloaded function AddSnapshotListener matches the argument list 没有重载函数findcontours的实例与参数列表匹配 - No instance of overloaded function findcontours matches the argument list 没有重载函数“”的实例与参数列表错误匹配 - no instance of overloaded function “” matches the argument list error 没有重载的实例 function “AfxBeginThread” 与参数列表匹配 - no instance of overloaded function "AfxBeginThread" matches the argument list 错误:没有重载函数“ mbed :: Ticker :: attach”的实例与参数列表匹配 - Error: No instance of overloaded function “mbed::Ticker::attach” matches the argument list KEIL错误:没有重载函数“ std :: transform”的实例与参数列表匹配 - KEIL error: no instance of overloaded function “std::transform” matches the argument list
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM