为 ARM 平台构建时要为 NTSTATUS 包含什么标头? [英] What header to include for an NTSTATUS when building for ARM platforms?

查看:11
本文介绍了为 ARM 平台构建时要为 NTSTATUS 包含什么标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 VS2013 ARM Developer Prompt 下工作.我正在尝试使用 Microsoft 的下一代加密技术 (CNG),但遇到了一些不小的问题.

I'm working under the VS2013 ARM Developer Prompt. I'm trying to use Microsoft's Cryptography Next Generation (CNG), but I'm experiencing some non-trivial problems.

我正在尝试编译一个简单的测试程序:

I'm trying to compile a simple test program:

#include <windows.h>
#include <bcrypt.h>

int main(int argc, char* argv[])
{
    BCRYPT_ALG_HANDLE hProvider = NULL;
    NTSTATUS ret = BCryptOpenAlgorithmProvider(&hProvider, BCRYPT_RNG_ALGORITHM, MS_PRIMITIVE_PROVIDER, 0);
    if (!(BCRYPT_SUCCESS(ret)))
    {
        return -1;
    }

    unsigned char buffer[20];
    ret = BCryptGenRandom(hProvider, buffer, (ULONG)sizeof(buffer), 0);
    if (!(BCRYPT_SUCCESS(ret)))
    {
        return -2;
    }

    ret = BCryptCloseAlgorithmProvider(hProvider, 0);
    if (!(BCRYPT_SUCCESS(ret)))
    {
        return -3;
    }

    return 0;
}

我尝试编译它:

C:UsersTest>cl.exe /nologo /W4 /D_MBCS /Zi /TP /EHs c /MD /FI sdkddkver.h /FI winapifamily.h /DWINAPI_FAMILY=WINAPI_FAMILY_APP /c test.cxx
Microsoft (R) C/C++ Optimizing Compiler Version 18.00.21005.1 for ARM
Copyright (C) Microsoft Corporation.  All rights reserved.

test.cxx
test.cxx(6) : error C2065: 'BCRYPT_ALG_HANDLE' : undeclared identifier
test.cxx(6) : error C2146: syntax error : missing ';' before identifier 'hProvid
er'
test.cxx(6) : error C2065: 'hProvider' : undeclared identifier
test.cxx(7) : error C2065: 'NTSTATUS' : undeclared identifier
test.cxx(7) : error C2146: syntax error : missing ';' before identifier 'ret'
test.cxx(7) : error C2065: 'ret' : undeclared identifier
test.cxx(7) : error C2065: 'hProvider' : undeclared identifier
test.cxx(7) : error C2065: 'BCRYPT_RNG_ALGORITHM' : undeclared identifier
test.cxx(7) : error C2065: 'MS_PRIMITIVE_PROVIDER' : undeclared identifier
test.cxx(7) : error C3861: 'BCryptOpenAlgorithmProvider': identifier not found
test.cxx(8) : error C2065: 'ret' : undeclared identifier
test.cxx(8) : error C3861: 'BCRYPT_SUCCESS': identifier not found
test.cxx(14) : error C2065: 'ret' : undeclared identifier
test.cxx(14) : error C2065: 'hProvider' : undeclared identifier
test.cxx(14) : error C3861: 'BCryptGenRandom': identifier not found
test.cxx(15) : error C2065: 'ret' : undeclared identifier
test.cxx(15) : error C3861: 'BCRYPT_SUCCESS': identifier not found
test.cxx(20) : error C2065: 'ret' : undeclared identifier
test.cxx(20) : error C2065: 'hProvider' : undeclared identifier
test.cxx(20) : error C3861: 'BCryptCloseAlgorithmProvider': identifier not found

test.cxx(21) : error C2065: 'ret' : undeclared identifier
test.cxx(21) : error C3861: 'BCRYPT_SUCCESS': identifier not found

当我尝试包含 <ntstatus.h> 时(从 PJ Naughter 的博客 因为我似乎无法从 Microsoft 找到任何有用的东西):

When I attempt to include <ntstatus.h> (scrapped from PJ Naughter's blog because I can't seem to find anything useful from Microsoft):

cl.exe /nologo /W4 /D_MBCS /Zi /TP /EHsc /MD /FI sdkddkver.h /FI winapifamily.h /DWINAPI_FAMILY=WINAPI_FAMILY_APP /c osrng.cpp
osrng.cpp
C:Program Files (x86)Windows Kits8.1includeshared
tstatus.h(66) : warning
C4005: 'STATUS_WAIT_0' : macro redefinition
        C:Program Files (x86)Windows Kits8.1includeumwinnt.h(2202) : see p
revious definition of 'STATUS_WAIT_0'
C:Program Files (x86)Windows Kits8.1includeshared
tstatus.h(212) : warning
 C4005: 'STATUS_ABANDONED_WAIT_0' : macro redefinition
        C:Program Files (x86)Windows Kits8.1includeumwinnt.h(2203) : see p
revious definition of 'STATUS_ABANDONED_WAIT_0'
C:Program Files (x86)Windows Kits8.1includeshared
tstatus.h(235) : warning
 C4005: 'STATUS_USER_APC' : macro redefinition
...

我无法将其设为 LONG,因为像 BCRYPT_SUCCESS 这样的 Microsoft 宏会将其转换为 NTSTATUS 代码.

I can't make it a LONG because Microsoft macros like BCRYPT_SUCCESS cast it to a NTSTATUS code.

我也可以在VS2012 ARM Developer Prompt下复制缺少NTSTATUS的问题.

I can also duplicate the missing NTSTATUS problem under VS2012 ARM Developer Prompt.

我应该包含什么头文件来获得 ARM 下 NTSTATUS 的声明?

What header file should I include to get a declaration for NTSTATUS under ARM?

认为这可能是相关的,但我不确定:致命错误 LNK1104:无法打开文件'bcrypt.lib' 为 Surface RT 平板电脑构建时.我所知道的只是这些东西似乎没有经过 Microsoft 的良好测试,因为尝试使用它时出现了太多该死的问题.

I think this might be related, but I'm not certain: fatal error LNK1104: cannot open file 'bcrypt.lib' when building for Surface RT tablet. About all I know is this stuff does not appear to be well tested by Microsoft because there are too many damn problems trying to use it.

推荐答案

主要问题是通用 Windows 平台应用(即 Windows 10 应用商店应用)支持 BCRYPT,但支持适用于 Windows 8.x 应用商店应用程序.VS 2013 工具集始终使用 Windows 8.1 SDK,因此您正在构建 Windows 8.1 应用商店应用程序.当您尝试 VS 2012 时,您使用的是 Windows 8.0 SDK,因此您正在构建 Windows 8.0 应用商店应用程序.同样,这两个都不支持 BCRYPT.如果您使用 VS 2015 构建并安装了 Windows 10 SDK,那么您的代码构建良好.

The main issue is that BCRYPT is supported for the Universal Windows Platform apps (aka Windows 10 Store apps), but was not supported for Windows 8.x Store apps. VS 2013 toolset always uses the Windows 8.1 SDK so you were building a Windows 8.1 Store app. When you tried VS 2012, you were using the Windows 8.0 SDK so you were building a Windows 8.0 Store apps. Again, neither of this support BCRYPT. If you build with VS 2015 and have the Windows 10 SDK installed, then your code builds fine.

请注意,/D_MBCS 不是 Windows 应用商店应用程序的选项.所有 Windows 应用商店应用程序都应该为 Unicode /DUNICODE/D_UNICODE 而不是您尝试做的 ANSI/Multibyte 构建.

Note that /D_MBCS is not an option for Windows Store apps. All Windows Store apps should be built for Unicode /DUNICODE /D_UNICODE and not ANSI/Multibyte as you were trying to do.

另外,请务必与 windowsapp.lib 链接,以确保在链接时选择正确的 DLL.

Also, be sure to link with windowsapp.lib to make sure you pick up the correct DLLs when you link.

如果文件中根本没有 #include <bcrypt.h>,您可以轻松确认您看到的所有错误都发生在 VS 2012/2013 中.DWINAPI_FAMILY=WINAPI_FAMILY_APP 确保所有不受支持的 API 都是未定义的,因此对于 Windows 8.x Store,该标头基本上是一个空文件.

You can easily confirm that all the errors you are seeing happen in VS 2012/2013 if you do not have #include <bcrypt.h> in the file at all. The DWINAPI_FAMILY=WINAPI_FAMILY_APP ensures that all unsupported APIs are undefined, so with Windows 8.x Store that header was basically an empty file.

这篇关于为 ARM 平台构建时要为 NTSTATUS 包含什么标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆