Windows :: Storage :: ApplicationData ::当前未在C中找到

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

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

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

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

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

我可以通过打开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

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

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

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

>从dllmain.cpp中删除四个Dll *()函数.您将依赖于从vccorlib链接的定义.请注意,仍然需要类注册(ActivatableClass(CGrayscale)).
>在C预处理器选项中,确保在“预处理器定义”中定义_WINRT_DLL.
>在链接器输入选项中,删除“模块定义文件”.

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

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

相关文章
相关标签/搜索