Windows::Storage::ApplicationData::当前未在C++; 我的C++代码,它是能够在Windows商店应用程序(Metro)中运行的一部分
我修改了Windows::Storage::ApplicationData::当前未在C++; 我的C++代码,它是能够在Windows商店应用程序(Metro)中运行的一部分,c++,visual-studio,visual-c++,windows-8,windows-runtime,C++,Visual Studio,Visual C++,Windows 8,Windows Runtime,我修改了C++灰度转换文件,以包含以下代码 < >但是,我的C++代码找不到命名空间 Windows::存储< /COL> LPCWSTR zPath = Windows::Storage::ApplicationData::Current->TemporaryFolder->Path->Data(); 是否需要进行其他设置 我可以通过启用使用Windows运行时扩展来编译它 但这样做,它会给我额外的链接错误和警告 warning LNK4197: export 'Dll
C++灰度转换文件
,以包含以下代码
< >但是,我的C++代码找不到命名空间<代码> Windows::存储< /COL>
LPCWSTR zPath = Windows::Storage::ApplicationData::Current->TemporaryFolder->Path->Data();
是否需要进行其他设置
我可以通过启用使用Windows运行时扩展来编译它
但这样做,它会给我额外的链接错误和警告
warning LNK4197: export 'DllGetActivationFactory' specified multiple times; using first specification
warning LNK4197: export 'DllCanUnloadNow' specified multiple times; using first specification
warning LNK4197: export 'DllGetActivationFactory' specified multiple times; using first specification
warning LNK4197: export 'DllCanUnloadNow' specified multiple times; using first specification
error LNK2005: _DllCanUnloadNow@0 already defined in dllmain.obj
error LNK1169: one or more multiply defined symbols found
注释掉DllCanUnloadNow
将产生运行时错误
我有一个运行时休息时间
// GrayscaleTransform.dll!Microsoft::WRL::Details::ModuleBase::ModuleBase() Line 155 + 0x46 bytes C++
ModuleBase() throw()
{
#ifdef _DEBUG
// This indicates that there were two instances of the module created or race conditon during module creation
// If you are creating object with new/delete please make sure that you haven't created more than one module
// and you disabled static initalization with __WRL_DISABLE_STATIC_INITIALIZE__
// otherwise please initialize/create module in main()
__WRL_ASSERT__(::InterlockedCompareExchangePointer(reinterpret_cast<void* volatile*>(&module_), this, nullptr) == nullptr &&
"The module was already instantiated");
SRWLOCK initSRWLOCK = SRWLOCK_INIT;
__WRL_ASSERT__(reinterpret_cast<SRWLOCK*>(&moduleLock_)->Ptr == initSRWLOCK.Ptr && "Different value for moduleLock_ than SRWLOCK_INIT");
(initSRWLOCK);
#else
module_ = this;
#endif
}
//GrayscaleTransform.dll!微软::WRL::细节:MeaveBase::MeaveBase.()行155 +0x46字节C++
ModuleBase()抛出()
{
#ifdef_调试
//这表示在模块创建期间创建了两个模块实例或竞争条件
//如果您正在使用new/delete创建对象,请确保您没有创建多个模块
//您使用uu WRL_DISABLE_static_INITIALIZE禁用了静态初始化__
//否则请在main()中初始化/创建模块
__WRL_ASSERT_uuuuuuuu(::InterlocatedCompareeExchangePointer(重新解释转换(&module_uuu)),this,nullptr==nullptr&&
“模块已实例化”);
SRWLOCK initSRWLOCK=SRWLOCK_INIT;
__WRL_ASSERT_uuuuu(重新解释强制转换(&moduleLock)->Ptr==initSRWLOCK.Ptr&“moduleLock与SRWLOCK_INIT的值不同”);
(initSRWLOCK);
#否则
模块=此;
#恩迪夫
}
发生链接器错误是因为您在GrayscaleTransform项目中启用了C++/CX。您的项目在dllmain.cpp中定义列出的入口点。当您启用C++/CX时,vccorlib将链接到您的模块中,并且它还定义了这些入口点
发生运行时错误的原因是vccorlib中的C++/CX基础结构创建了一个模块,而您的入口点尝试创建不同类型的模块。一个模块中只能有一个模块
您需要对GrayscaleTransform项目进行更多更改,以便能够在其中使用C++/CX:
- 从dllmain.cpp中删除四个Dll*()函数。您将依赖于从vccorlib链接的定义。请注意,仍然需要类注册(
)ActivatableClass(CGrayscale)
- 在链接器输入选项中,删除“模块定义文件”
P>可选地,考虑不要使用C++或CX,而是在整个项目中使用WRL。这将更加详细,但如果您已经在项目的其他部分使用WRL,则可能更有意义。谢谢。按照你提到的3个步骤,它现在就解决了。