gpt4 book ai didi

c++ - Windows::Storage::ApplicationData::Current 在 C++ 中找不到

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:24:23 25 4
gpt4 key购买 nike

我的 C++ 代码,属于 Media Foundation Transform 的一部分倾向于能够在 Windows Store App (Metro) 中运行

我修改了 C++ GrayscaleTransform 以包含以下代码。

但是,我的 C++ 代码无法找到命名空间 Windows::Storage

LPCWSTR zPath = Windows::Storage::ApplicationData::Current->TemporaryFolder->Path->Data();

我需要做任何额外的设置吗?

我可以通过打开使用 Windows 运行时扩展 来编译它。

enter image description here

但是通过这样做,它会给我额外的链接错误和警告。

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 项目中启用了 C++/CX。您的项目定义了 dllmain.cpp 中列出的入口点。当您启用 C++/CX 时,vccorlib 会链接到您的模块中,它还会定义这些入口点。

运行时错误的发生是因为 vccorlib 中的 C++/CX 基础结构创建了一个模块,而您的入口点试图创建一种不同类型的模块。一个模块中只能有一个模块。

您需要对 GrayscaleTransform 项目进行更多更改才能在其中使用 C++/CX:

  • 从 dllmain.cpp 中删除四个 Dll*() 函数。您将依赖从 vccorlib 链接的定义。请注意,类注册 (ActivatableClass(CGrayscale)) 仍然是必需的。

  • 在 C++ 预处理器选项中,确保 _WINRT_DLL 在“预处理器定义”中定义。

  • 在链接器输入选项中,删除“模块定义文件”。

请注意,在使用 WRL 混合使用 C++/CX 和“低级”C++ 时,您需要非常小心。大多数涉及 C++/CX 类型的表达式都可能引发异常,您必须确保不允许任何异常跨越 ABI 边界。

或者,考虑不使用 C++/CX,而是在整个项目中使用 WRL。它会更冗长,但如果您已经在项目的其他部分使用 WRL,它可能更有意义。

关于c++ - Windows::Storage::ApplicationData::Current 在 C++ 中找不到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12893355/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com