dll - 如何在 Win32 桌面应用程序中使用自定义 WinRT 库?

标签 dll windows-8 windows-runtime c++-cx

我的基于 Win32 的桌面应用程序中有一个 WinRT 类(C++/CX 引用类)。它访问 WinRT API 并且工作得很好。我用了this guide让它工作。现在我正在尝试将此类放入桌面应用程序可以使用的库中。我在这方面遇到了很多麻烦。这是我在 Visual Studio 2013 中所做的:

  • 通过选择 Installed > Templates > Visual C++ > Store Apps > Windows Apps > DLL (Windows) 创建了一个新项目。
  • 将这个新的 DLL 项目添加到包含我的桌面应用程序的解决方案中。
  • 添加了对 DLL 项目的引用
  • 在 Configuration Properties > C/C++ > General > Additional #using Directories 中,我添加了 .winmd 文件由 DLL 项目构建的目录。
  • 在桌面应用程序的 .cpp 文件中,我添加了:

  • #using <MyLib.winmd>
    #using <Windows.winmd>
    #using <Platform.winmd>
    
    [MTAThread] // initializes WinRT runtime
    int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
                         _In_opt_ HINSTANCE hPrevInstance,
                         _In_ LPTSTR    lpCmdLine,
                         _In_ int       nCmdShow) {
        MyWinRTClass^ myObject = ref new MyWinRTClass();
    }
    

    Intellisense 工作,我编写了代码来实例化库中的类。桌面应用程序构建,但是当它运行时我得到:

    First-chance exception at 0x76494598 in MyDesktopApp.exe: Microsoft C++ exception: Platform::ClassNotRegisteredException ^ at memory location 0x00A8F99C.



    这是怎么回事?这是正确的方法吗?

    最佳答案

    截至 2019 年 7 月 26 日的更新:请参阅以下线程中“Adam Braden - MSFT”的评论。

    这是不可能的。为了让应用程序使用自定义 WinRT 组件,需要先“注册”该组件。对于打包 (AppX) 应用程序,这是通过将一些信息添加到包的 AppXManifest.xml 中来完成的。但是,对于常规 Win32 桌面应用程序,现在可以进行此类注册。您可以直接调用操作系统提供的 WinRT API,但不能写入自己的自定义 WinRT API 以供其他应用程序使用。

    关于dll - 如何在 Win32 桌面应用程序中使用自定义 WinRT 库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29761911/

    相关文章:

    python - 构建 DLL (MyMathFuncs) 以在 Python Ctypes 中使用

    c# - 在 WCF 客户端应用程序之间共享静态 dll

    java - tools.jar 似乎不在 Windows 8 上的 Android Studio 类路径中

    windows-runtime - 在 Windows 8 中创建类似 3D 道路的效果

    performance - 图像需要很长时间才能加载 WinRT XAML

    .net - 在 Visual Studio 安装项目中将 DLL 部署到 GAC 时出现问题

    c++ - 将一组函数同时编译成.LIB和.DLL

    c# - 为什么 ItemsSource 不绑定(bind)到我的自定义 CollectionChanged 事件

    c# - System.ComponentModel.TypeConverter 的 WinRT 替换

    windows - MvvmCross Windows Phone 8.1 绑定(bind)列表选择到命令,编译失败