Windows :: Storage :: ApplicationData ::当前在C++中找不到

Che*_*eng 4 c++ visual-studio visual-c++ windows-8 windows-runtime

我的C++代码,它是Media Foundation Transform的一部分,往往能够在Windows应用商店应用(Metro)中运行

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

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

LPCWSTR zPath = Windows::Storage::ApplicationData::Current->TemporaryFolder->Path->Data();
Run Code Online (Sandbox Code Playgroud)

我需要做任何其他设置吗?

我可以通过打开Consume Windows Runtime Extension来编译它.

在此输入图像描述

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

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
Run Code Online (Sandbox Code Playgroud)

注释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
    }
Run Code Online (Sandbox Code Playgroud)

Jam*_*lis 8

发生链接器错误是因为您在GrayscaleTransform项目中启用了C++/CX.您的项目定义了dllmain.cpp中列出的入口点.启用C++/CX时,vccorlib会链接到您的模块中,并且还会定义这些入口点.

发生运行时错误是因为vccorlib中的C++/CX基础结构创建了一个模块,并且您的入口点尝试创建另一种模块.模块中只能有一个模块.

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

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

  • 在C++预处理器选项中,确保_WINRT_DLL在"预处理器定义"中定义.

  • 在链接器输入选项中,删除"模块定义文件".

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

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