WinRT库不工作在释放模式 [英] WinRT library not working in Release mode

查看:300
本文介绍了WinRT库不工作在释放模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图在Visual Studio 2012中使用WinRT库构建桌面应用程序。
代码片段如下。

  [STAThread] 
int wmain(Platform :: Array< String ^> ^ args)
{
wcout<< L版权所有(c)Microsoft Corporation。保留所有权利。 << endl;
wcout<< LFindPackages sample< endl<< endl;
try
{
auto packageManager = ref new Windows :: Management :: Deployment :: PackageManager();
auto packages = packageManager-> FindPackages();

int packageCount = 0;
std :: for_each(Windows :: Foundation :: Collections :: begin(packages),Windows :: Foundation :: Collections :: end(packages),
[& packageManager,& packageCount] (Windows :: ApplicationModel :: Package ^ package)
{
DisplayPackageInfo(package);
DisplayPackageUsers(packageManager,package);
wcout<< endl;
packageCount + = 1;
});
}
catch(AccessDeniedException ^)
{
wcout< LFindPackagesSample失败,因为访问被拒绝。此程序必须从提升的命令提示符下运行。 << endl;
return 1;
}
catch(Exception ^ ex)
{
wcout<< LFindPackagesSample failed,error message:<< > ToString() - > Data()<< endl;
return 1;
}
getchar();
return 0;

}



地铁应用程序详细信息。并且这个代码在DEBUG模式下工作正常。但是当我把它改为释放模式,我得到一个错误:

 错误LNK2001:未解决的外部符号_NtProcessStartup 

注意:
我更改了某些设置,如

配置属性 - C / C ++ - > COnsume Windows运行时异常为是(/ ZW)
配置属性 - > C / C ++ - >代码生成 - >最小重建为NO(/ gm-)
配置属性 - > C / C ++ - >代码生成 - >运行时LIbrary到多线程DLL(/ MD)



它被告知这些设置是WinRT必须的图书馆包容。
所以基本上,我必须在发布模式下以Multi_Threaded(/ MT)格式运行我的代码。但/ MT或/ Mtd与WinRT库所需的(/ ZW)方法不兼容。
请指导我的错误。

解决方案

你得到一个关于缺少NtProcessStartup符号的消息意味着使用了链接器开关 / SUBSYSTEM:NATIVE 。因为这在唯一的选项,需要一个NtProcessStartup函数,而不是wmain / main。所以你的发布模式选项以某种方式将你的应用程序标记为NATIVE(通常是设备驱动程序)应用程序。 (或者你特别添加了一个/ ENTRY:NtProcessStartup,但对我来说似乎不太可能)。


I've have been trying to build a desktop application using WinRT libraries in Visual Studio 2012. The code snippet goes as follows.

[STAThread] 
int   wmain (Platform :: Array <String ^> ^ args) 
{ 
    wcout << L"Copyright (c) Microsoft Corporation. All rights reserved." << endl; 
wcout << L"FindPackages sample" << endl << endl; 
 try 
{ 
    auto packageManager = ref new Windows::Management::Deployment::PackageManager(); 
    auto packages = packageManager->FindPackages();

    int packageCount = 0; 
    std::for_each(Windows::Foundation::Collections::begin(packages), Windows::Foundation::Collections::end(packages), 
        [&packageManager, &packageCount](Windows::ApplicationModel::Package^ package)  
    {  
        DisplayPackageInfo(package); 
        DisplayPackageUsers(packageManager, package); 
        wcout << endl; 
        packageCount += 1;  
    }); 
} 
catch (AccessDeniedException^) 
{ 
    wcout << L"FindPackagesSample failed because access was denied. This program must be run from an elevated command prompt." << endl; 
    return 1; 
} 
catch (Exception^ ex) 
{ 
    wcout << L"FindPackagesSample failed, error message: " << ex->ToString()->Data() << endl; 
    return 1; 
} 
getchar();
return 0; 

}

This is used to list the metro apps details. And this code works fine in DEBUG mode. But when I change it to release mode, I am getting an error:

error LNK2001: unresolved external symbol _NtProcessStartup 

NOTE: I've changed certain settings such as
Configuration properties -> C/C++-> COnsume Windows Runtime Exception to Yes(/ZW)
Configuration properties -> C/C++-> Code Generation-> Enable Minimal Rebuild to NO(/gm-)
Configuration properties -> C/C++-> Code Generation-> Runtime LIbrary to Multi-threaded DLL(/MD)

Its been told that these settings are mandatory for WinRT library inclusion. So basically, I have to run my code in Multi_Threaded (/MT) format for Release mode. But /MT or /Mtd is not compatible with (/ZW) method which is necessary for WinRT libraries. Please guide me on my mistakes.

解决方案

The fact that you get a message about a missing NtProcessStartup symbol implies that the linker switch /SUBSYSTEM:NATIVE was used. Because this in the only option that requires a NtProcessStartup function instead of wmain/main. So your release mode options have somehow marked your application as a NATIVE (usually device driver) application. (Or you specifically added a /ENTRY:NtProcessStartup but that seems very unlikely to me).

这篇关于WinRT库不工作在释放模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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