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

2024-03-22

我的 C++ 代码,它是媒体基础转型 http://code.msdn.microsoft.com/windowsapps/Media-Capture-Sample-adf87622往往能够在 Windows 应用商店应用程序 (Metro) 中运行

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

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

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

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

您需要对灰度变换项目进行一些更改才能在其中使用 C++/CX:

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

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

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

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

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 C++ 中找不到 Windows::Storage::ApplicationData::Current 的相关文章