Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 检查windows激活状态返回错误的值_C++_Winapi_Activation - Fatal编程技术网

C++ 检查windows激活状态返回错误的值

C++ 检查windows激活状态返回错误的值,c++,winapi,activation,C++,Winapi,Activation,我正在为windows 10构建一个桌面应用程序,用于检查windows是否已激活。我正在使用另一个线程上找到的方法来检查激活状态,该方法仅在创建窗口的几秒钟内被调用时才有效。奇怪,我知道。有人知道这可能是什么原因吗?如果我能做些什么来修复它?感谢您的帮助 bool isGenuineWindows() { //WindowsAppId unsigned char uuid_bytes[] = {0x35, 0x35, 0x63, 0x39, 0x32, 0x37, 0x33,

我正在为windows 10构建一个桌面应用程序,用于检查windows是否已激活。我正在使用另一个线程上找到的方法来检查激活状态,该方法仅在创建窗口的几秒钟内被调用时才有效。奇怪,我知道。有人知道这可能是什么原因吗?如果我能做些什么来修复它?感谢您的帮助

bool isGenuineWindows()
{
    //WindowsAppId
    unsigned char uuid_bytes[] = {0x35, 0x35, 0x63, 0x39, 0x32, 0x37, 0x33, 0x34, 0x2d, 0x64, 0x36,
                                0x38, 0x32, 0x2d, 0x34, 0x64, 0x37, 0x31, 0x2d, 0x39, 0x38, 0x33,
                                0x65, 0x2d, 0x64, 0x36, 0x65, 0x63, 0x33, 0x66, 0x31, 0x36, 0x30,
                                0x35, 0x39, 0x66};

    GUID uuid;
    SL_GENUINE_STATE state;

    UuidFromStringA(uuid_bytes, &uuid);
    SLIsGenuineLocal(&uuid, &state, nullptr);
    return state == SL_GEN_STATE_IS_GENUINE;
}

int main(void)
{
      /*creates GUI and all that boring stuff*/
      MessageBox(NULL, "Some random message", "message", MB_ICONERROR);
      printf("%d", isGenuineWindows()); //works
      Sleep(5000); //wait a bit for the magic to wear off
      printf("%d", isGenuineWindows()); //always returns true regardless of activation state
      MessageBox(NULL, "Some random message", "message", MB_ICONERROR);
      printf("%d", isGenuineWindows()); //works again
}


UuidFromStringA
的第一个参数类型是RPC_CSTR,它在rpcdce.h中定义:

typedef _Null_terminated_ unsigned char __RPC_FAR * RPC_CSTR;
它是一个以NULL结尾的字符串,尽管没有文档记录。 如果参数不是以NULL结尾,则函数将失败。您传递的字符串不是以NULL结尾的,这将导致未定义的行为(取决于uuid_字节的原始值[36])

使用纯文本字符串而不是ASCII,ASCII是默认的以NULL结尾的字符串:

unsigned char uuid_bytes[] = "55c92734-d682-4d71-983e-d6ec3f16059f";

不检查返回值。这就是你判断函数是否成功的方法。您的字符串不是以null结尾的。为什么不使用字符串,这样更容易看出它实际上是什么。但在步骤1中,添加缺少的错误检查。@正在检查DavidFeffernan返回值。它们只是用printf打印为0或1。这不是一种理想的方法,但它们是经过检查的<代码>返回状态==SL_GEN_state_是真正的@Zachary你所说的`//works`是什么意思然后
//总是返回true
printf是否为你打印两个不同的值?由于windows已激活,它是否总是返回true?printf是否返回false和second true?您的问题有点不清楚。@尼娜:不,api调用的返回值不清楚checked@Nina第一个printf返回真实的激活状态。无论windows是否被激活,第二种情况总是正确的。再次打开messagebox后,它将打印正确的输出。例如,如果windows未激活,它将打印010,如果它被激活,它将打印111。我知道printf不是一个很好的方法,它只是一个概念证明。@DavidHeffernan你是对的,我应该检查SLIsGenuineLocal返回的错误,但我只是没有在这里实现它。我以前检查过退货,没有错误。