VS2010 - CryptoAPI中的结构更改 - v7.0A Vs v6.0A - WinCrypt.h [英] VS2010 - Structure change in CryptoAPI - v7.0A Vs v6.0A - WinCrypt.h
问题描述
在 C:\Program Files \Microsoft SDKs\Windows \v7.0A\Include\WinCrypt.h
中, CERT_CHAIN_ENGINE_CONFIG
是
typedef struct _CERT_CHAIN_ENGINE_CONFIG {
DWORD cbSize ;
HCERTSTORE hRestrictedRoot;
HCERTSTORE hRestrictedTrust;
HCERTSTORE hRestrictedOther;
DWORD cAdditionalStore;
HCERTSTORE * rghAdditionalStore;
DWORD dwFlags;
DWORD dwUrlRetrievalTimeout; // milliseconds
DWORD MaximumCachedCertificates;
DWORD CycleDetectionModulus;
*#if(NTDDI_VERSION> = NTDDI_WIN7)
HCERTSTORE hExclusiveRoot;
HCERTSTORE hExclusiveTrustedPeople;
#endif *
} CERT_CHAIN_ENGINE_CONFIG,* PCERT_CHAIN_ENGINE_CONFIG;
我在XP sp3机器上使用visual studio 2010,在这种情况下,在上述结构中的两个成员变灰。但这不会发生,
#if(NTDDI_VERSION> = NTDDI_WIN7)
HCERTSTORE hExclusiveRoot;
HCERTSTORE hExclusiveTrustedPeople;
#endif
NTDDI_VERSION
-turn在 sdkddkver.h
中定义如下, _WIN32_WINNT
某种方式取值 NTDDI_WIN7
这在我的情况是不正确的,因为我是一个XP SP3机器。
#if! (_WIN32_WINNT)&& !defined(_CHICAGO_)
#define _WIN32_WINNT 0x0601
#endif
#ifndef NTDDI_VERSION
#ifdef _WIN32_WINNT
//根据_WIN32_WINNT设置NTDDI_VERSION
#define NTDDI_VERSION NTDDI_VERSION_FROM_WIN32_WINNT(_WIN32_WINNT)
#else
#define NTDDI_VERSION 0x06010000
#endif
#endif
$有问题的结构 CERT_CHAIN_ENGINE_CONFIG
的上述两个成员不存在于 C:\Program Files \\ \\ Microsoft Windows SDK \ Windows \v6.0A \Include \WinCrypt.h
但是我的2010年的Visual Studio项目自动从 C: \\ Program Files \Microsoft SDKs \Windows \v7.0A\Include\WinCrypt.h
因为冲突的结构,我得到参数不正确
请告诉我如何解决这个问题?
visual studio 2010 sp1?
我。通常,在预处理器定义内的Visual Studio项目的设置中执行此操作。如果你这样做, CERT_CHAIN_ENGINE_CONFIG
结构的相应部分将显示为灰色,就像你想要的那样。
大多数情况下和 CERT_CHAIN_ENGINE_CONFIG
的情况下,它不是真的需要。 Windows API的设计主要是这样的,如果在Windows XP上启动程序,您在使用为Windows 7定义的 CERT_CHAIN_ENGINE_CONFIG
中没有问题。如果你定义
#define WINVER 0x0500
#define _WIN32_WINNT 0x0500
(或 0x0501
,而不是 0x0500
),您将能够在Windows 7中运行您的程序,但是您将无法使用 hExclusiveRoot
和 hExclusiveTrustedPeople
成员。原因是 cbSize
字段,您应该初始化为 sizeof(CERT_CHAIN_ENGINE_CONFIG)
。它为 CertCreateCertificateChainEngine 函数提供有关输入结构大小的足够信息 CERT_CHAIN_ENGINE_CONFIG
。在 cbSize
的值很小的情况下,最后的 HCERTSTORE
成员 hExclusiveRoot
和 hExclusiveTrustedPeople
将不会使用。
In C:\Program Files\Microsoft SDKs\Windows\v7.0A\Include\WinCrypt.h
, the definition for CERT_CHAIN_ENGINE_CONFIG
is
typedef struct _CERT_CHAIN_ENGINE_CONFIG {
DWORD cbSize;
HCERTSTORE hRestrictedRoot;
HCERTSTORE hRestrictedTrust;
HCERTSTORE hRestrictedOther;
DWORD cAdditionalStore;
HCERTSTORE* rghAdditionalStore;
DWORD dwFlags;
DWORD dwUrlRetrievalTimeout; // milliseconds
DWORD MaximumCachedCertificates;
DWORD CycleDetectionModulus;
*#if (NTDDI_VERSION >= NTDDI_WIN7)
HCERTSTORE hExclusiveRoot;
HCERTSTORE hExclusiveTrustedPeople;
#endif*
} CERT_CHAIN_ENGINE_CONFIG, *PCERT_CHAIN_ENGINE_CONFIG;
I am using visual studio 2010 in an XP sp3 machine, in which case, i expect that the following two members in the above structure gets greyed out. But this is not happening,
#if (NTDDI_VERSION >= NTDDI_WIN7)
HCERTSTORE hExclusiveRoot;
HCERTSTORE hExclusiveTrustedPeople;
#endif
NTDDI_VERSION
in-turn is defined in sdkddkver.h
as follows, and _WIN32_WINNT
somehow takes the value of NTDDI_WIN7
which in my case is incorrect as mine is a XP SP3 machine.
#if !defined(_WIN32_WINNT) && !defined(_CHICAGO_)
#define _WIN32_WINNT 0x0601
#endif
#ifndef NTDDI_VERSION
#ifdef _WIN32_WINNT
// set NTDDI_VERSION based on _WIN32_WINNT
#define NTDDI_VERSION NTDDI_VERSION_FROM_WIN32_WINNT(_WIN32_WINNT)
#else
#define NTDDI_VERSION 0x06010000
#endif
#endif
The above two members of the structure CERT_CHAIN_ENGINE_CONFIG
in question is not present in C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include\WinCrypt.h
But my 2010 visual studio project automatically pulls in the header and lib files from C:\Program Files\Microsoft SDKs\Windows\v7.0A\Include\WinCrypt.h
Because of the conflicting structures, i am getting parameter is incorrect
Please advise how i can over come this issue?
Should i have to install visual studio 2010 sp1?
I found one reference in the web where it says initialising the structure will resolve the issue, but it will not, as the two parameters in question will not be greyed out and will be taken in while building.
UPDATE1:
Settings of my project:
$(VCInstalDir) - >C:\Program Files\Microsoft Visual Studio 10.0\VC
$(WindowsSdkDir) ->C:\Program Files\Microsoft SDKs\Windows\v7.0A
$(FrameworkSdkDir) ->C:\Program Files\Microsoft SDKs\Windows\v7.0A
Library file settings,
$(VCInstallDir)lib
$(VCInstallDir)atlmfc\lib
$(WindowsSdkDir)lib
$(FrameworkSDKDir)\lib
UPDATE 2: My preprocessor definitions are
WIN32;_DEBUG;_WINDOWS;_USRDLL;MY_DLL_EXPORTS;%(PreprocessorDefinitions)
%(PreprocessorDefinitions) inherited values as follows
_WINDLL
_MBCS
Thanks
The problem which you have can be very easy explained. If you use v7.0A or v7.1 you are able to compile your project so that it will run under Windows 7. So the default value for the _WIN32_WINNT
is 0x0601
.
If you want co compile the program so that it will run on Windows XP you can define WINVER and _WIN32_WINNT explicitly. Typically one do this in the settings of the Visual Studio project inside of the preprocessor definitions. If you will do this the corresponding part of CERT_CHAIN_ENGINE_CONFIG
structure will be displayed gray like you as want.
In the most cases and in the case of CERT_CHAIN_ENGINE_CONFIG
it is not really needed. The Windows API are designed mostly so, that you will have no problems in the usage of CERT_CHAIN_ENGINE_CONFIG
defined for Windows 7 in case of the start of the program on Windows XP. If you do define
#define WINVER 0x0500
#define _WIN32_WINNT 0x0500
(or 0x0501
instead of 0x0500
) you will be able to run your program in the Windows 7, but you will be not able to use the hExclusiveRoot
and the hExclusiveTrustedPeople
members. The reason is the cbSize
field which you should initialize as sizeof(CERT_CHAIN_ENGINE_CONFIG)
. It gives for the CertCreateCertificateChainEngine function enough information about the size of the input structure CERT_CHAIN_ENGINE_CONFIG
. In case of small value of cbSize
, the last HCERTSTORE
members hExclusiveRoot
and hExclusiveTrustedPeople
will be just not used.
这篇关于VS2010 - CryptoAPI中的结构更改 - v7.0A Vs v6.0A - WinCrypt.h的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!