Windows::Storage::ApplicationData::Current 在 C++ 中找不到 [英] Windows::Storage::ApplicationData::Current Not Found in C++

查看:47
本文介绍了Windows::Storage::ApplicationData::Current 在 C++ 中找不到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 C++ 代码,它是 媒体基础转换的一部分 倾向于能够在 Windows Store App (Metro) 中运行

My C++ code, which is part of Media Foundation Transform tend to able to run in Windows Store App (Metro)

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

I modify the C++ GrayscaleTransform to include the following code.

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

However, my C++ code fails to locate namespace Windows::Storage.

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

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

Is there any additional settings I need to do?

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

I can make it compiled, by turning on Consume Windows Runtime Extension.

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

But by doing this, it will give me additional linking error and warnings.

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 会产生运行时错误.

Comment out DllCanUnloadNow will produce runtime error.

我在

// 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 会链接到您的模块中,并且它还定义了这些入口点.

The linker errors occur because you enabled C++/CX in the GrayscaleTransform project. Your project defines the listed entry points in dllmain.cpp. When you enable C++/CX, vccorlib gets linked into your module, and it also defines these entry points.

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

The runtime error occurs because the C++/CX infrastructure in vccorlib creates a Module, and your entry point tries to create a different kind of Module. There can only be one Module in a module.

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

You need to make a few more changes to the GrayscaleTransform project to be able to use C++/CX in it:

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

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

In the C++ Preprocessor options, ensure that _WINRT_DLL is defined in the "Preprocessor Definitions."

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

In the Linker input options, remove the "Module Definition File."

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

Note that you will need to be very careful when mixing C++/CX and "low-level" C++ using WRL. Most expressions that involve C++/CX types can throw exceptions, and you must ensure that no exceptions are ever allowed to cross the ABI boundary.

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

Alternatively, consider not using C++/CX and instead using WRL throughout your project. It will be more verbose, but if you are already using WRL for other parts of the project, it may make more sense.

这篇关于Windows::Storage::ApplicationData::Current 在 C++ 中找不到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆