使用C ++和bcrypt标头时编译错误 [英] Compile errors when using C++ and bcrypt header
问题描述
我正在尝试测试Windows Bcrypt。我有一个测试程序:
I'm trying to test Windows Bcrypt. I have a test program:
#include <bcrypt.h>
#include <iostream>
#include <string>
#pragma comment (lib, "bcrypt.lib")
int main(int argc, char* argv[])
{
return 0;
}
尝试对其进行编译:
>cl.exe /DWINVER=0x0600 /TP /GR /EHsc bcrypt-test.cpp /link /out:bcrypt-test.exe
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24210 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
bcrypt-test.cpp
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared\bcrypt.h(39):
error C2059: syntax error: 'return'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared\bcrypt.h(40):
error C2143: syntax error: missing ';' before '*'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared\bcrypt.h(40):
error C4430: missing type specifier - int assumed. Note: C++ does not support d
efault-int
...
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared\bcrypt.h(681)
: error C3646: 'cbKeyLength': unknown override specifier
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared\bcrypt.h(681)
: fatal error C1003: error count exceeds 100; stopping compilation
我正在使用 Visual C ++ x64 Build Tools 命令提示符。据我了解,Bcrypt需要针对Vista或更高版本。 WINVER = 0x0600
应该满足要求。我在MSDN论坛上的 bcrypt.h构建错误?,它表示要使用现代SDK。我相信Windows Kit SDK应该可以满足要求。
I am using a Visual C++ x64 Build Tools command prompt. As I understand things, Bcrypt needs to target Vista or above. WINVER=0x0600
should satisfy the requirement. I found a similar question on the MSDN forums at bcrypt.h build error?, and it says to use a modern SDK. I believe the Windows Kit SDK should satisfy the requirement.
为什么会遇到编译错误,以及如何解决?
Why am I experiencing compile errors, and how do I fix it?
bcrypt.h
中的第39行是下面的第一个typedef。为简便起见,跳过了序言,如版权保护和标头保护。
Line 39 in bcrypt.h
is the first typedef below. The preamble, like copyright and header guards, were skipped for brevity.
#ifndef WINAPI
#define WINAPI __stdcall
#endif
#ifndef _NTDEF_
typedef _Return_type_success_(return >= 0) LONG NTSTATUS;
typedef NTSTATUS *PNTSTATUS;
#endif
#ifndef BCRYPT_SUCCESS
#define BCRYPT_SUCCESS(Status) (((NTSTATUS)(Status)) >= 0)
#endif
推荐答案
您缺少一个包含项。
#include <Windows.h> // <- Added this
#include <bcrypt.h>
#include <iostream>
#include <string>
#pragma comment (lib, "bcrypt.lib")
int main()
{
return 0;
}
这篇关于使用C ++和bcrypt标头时编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!