简体   繁体   English

对于具有基于ATL的库的Windows应用商店,认证失败

[英]Certification fails for Windows Store App with ATL-based library

I have a Windows library developed in C++ that uses ATL collections, ATL CString and COM interfaces with CComPtr heavily. 我有一个用C ++开发的Windows库,它使用ATL集合,ATL CString和与CComPtr的COM接口。 I removed all non-winrt-allowed API calls from the library, and it builds fine, so I wrapped the library in a C++/CX ref-class and I am trying to use it from a Windows Store App. 我从库中删除了所有非winrt允许的API调用,并且构建正常,所以我将库包装在C ++ / CX ref-class中,我试图从Windows应用商店应用程序中使用它。 The application runs fine, but the Win-Store App certification fails with the following error: 应用程序运行正常,但Win-Store App认证失败,并出现以下错误:

Error Found: The supported APIs test detected the following errors: API GetModuleHandleW in kernel32.dll is not supported for this application type. 发现错误:支持的API测试检测到以下错误:此应用程序类型不支持kernel32.dll中的API GetModuleHandleW。 MyLibrary.dll calls this API. MyLibrary.dll调用此API。 API InitializeCriticalSectionAndSpinCount in kernel32.dll is not supported for this application type. 此应用程序类型不支持kernel32.dll中的API InitializeCriticalSectionAndSpinCount。 MyLibrary.dll calls this API. MyLibrary.dll调用此API。

The VS project for my library is configured for Windows Store with the following settings: 我的库的VS项目是为Windows应用商店配置的,具有以下设置:

在此输入图像描述

These settings activate/deactivate the required macros (WINAPI_FAMILY as WINAPI_FAMILY_APP for example) in the SDK as expected. 这些设置按预期激活/停用SDK中所需的宏(例如,WINAPI_FAMILY为WINAPI_FAMILY_APP)。

I am 100% sure I am not calling GetModuleHandleW or InitializeCriticalSectionAndSpinCount directly in my library, so I thought this issue must be coming from a method of some ATL class that was not filtered properly in the Windows 8 SDK. 我100%确定我没有直接在我的库中调用GetModuleHandleW或InitializeCriticalSectionAndSpinCount,所以我认为这个问题必须来自某个ATL类的方法,该方法未在Windows 8 SDK中正确过滤。

Diving into ATL header files was not very useful, since everything looks properly filtered there, for example see this fragment from ATL::CComCriticalSection::Init 潜入ATL头文件并不是很有用,因为所有东西看起来都在那里正确过滤,例如从ATL :: CComCriticalSection :: Init看到这个片段

#if !defined(_ATL_USE_WINAPI_FAMILY_DESKTOP_APP) || defined(_ATL_STATIC_LIB_IMPL)
        if (!_AtlInitializeCriticalSectionEx(&m_sec, 0, 0))
#else
        if (!InitializeCriticalSectionAndSpinCount(&m_sec, 0))
#endif

In order to prove my theory, I took an hex-editor and edited out GetModuleHandleW from my Kernel32.lib file, which gives me the following linking error: 为了证明我的理论,我使用了一个十六进制编辑器并从我的Kernel32.lib文件中编辑了GetModuleHandleW,这给了我以下链接错误:

atls.lib(atlwinverapi.obj) : error LNK2001: unresolved external symbol __imp__GetModuleHandleW@4 atls.lib(atlwinverapi.obj):错误LNK2001:未解析的外部符号__imp__GetModuleHandleW @ 4

So it seems my theory is not wrong. 所以看来我的理论没有错。 Note that I am doing all this using release builds, since debug builds do not pass the certification. 请注意,我正在使用发布版本执行所有这些操作,因为调试版本未通过认证。

Now the question: 现在的问题是:

Is there any way for me to know exactly which class inside ATL is sabotaging my library other than looking at the header files? 除了查看头文件之外,有什么办法可以让我确切地知道ATL中哪个类正在破坏我的库?

Same question in MSDN forums MSDN论坛中的相同问题

I have added a bug report on microsoft connect with a small sample code that reproduces this issue. 在微软连接上添加了一个错误报告,其中包含一个重现此问题的小示例代码。

Here is what I guess. 这是我猜的。 Look at the file atlwinverapi.h. 查看文件atlwinverapi.h。 There the macro _ATL_NTDDI_MIN is conditionally defined one way for x86/x64 and another way for ARM. 在那里,宏_ATL_NTDDI_MIN有条件地为x86 / x64定义了一种方式,而另一种方式定义为ARM。

I think this might have changed during the recent VSUpdate that added XP support. 我认为在最近添加XP支持的VSUpdate期间可能会发生这种变化。 Now in the file atlwinverapi.cpp (which goes into atls.lib I guess), in the method _AtlInitializeCriticalSectionEx, you will notice that it's calling InitializeCriticalSectionAndSpinCount if _ATL_NTDDI_MIN < NTDDI_VISTA. 现在在文件atlwinverapi.cpp(我想进入atls.lib),在_AtlInitializeCriticalSectionEx方法中,如果_ATL_NTDDI_MIN <NTDDI_VISTA,你会注意到它正在调用InitializeCriticalSectionAndSpinCount。

I am assuming your building x86 or x64 that's why you are seeing this problem. 我假设您正在构建x86或x64,这就是您遇到此问题的原因。 If you build for ARM, you will not see this problem. 如果为ARM构建,则不会看到此问题。

Of course you will not be able to run WACK on ARM but you can run dumpbin /imports on your binary and see if it still uses those non-compliant API. 当然,您将无法在ARM上运行WACK,但您可以在二进制文件上运行dumpbin / imports,看看它是否仍然使用这些不兼容的API。

Hope this link can help you. 希望这个链接可以帮到你。 It's from MSDN. 它来自MSDN。 http://ecn.channel9.msdn.com/events/Win8CppEvent/PortingToMetro.pptx http://ecn.channel9.msdn.com/events/Win8CppEvent/PortingToMetro.pptx

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM