相关疑难解决方法(0)

你能在UWP的C#代码中使用C++ DLL吗?

我在Visual Studio中编写了一个C++类库,它只定义了一个调用Python的函数:

#pragma once

#include <Python.h>

extern "C"
__declspec(dllexport)
void python()
{
    Py_Initialize();
    PyRun_SimpleString("2 + 2");
}
Run Code Online (Sandbox Code Playgroud)

我在同一个C#Blank Universal应用程序的解决方案中创建了另一个项目.我试图引用我之前提到的项目生成的DLL:

using System;
...

namespace StartupApp
{
    ...
    sealed partial class App : Application
    {
        private const string CPPPythonInterfaceDLL = @"pathtodll";

        [DllImport(CPPPythonInterfaceDLL, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern void python();

        public static void Python()
        {
            python();
        }
        ...
        public App()
        {
            ...

            Python();
        }

        ...
    }
}
Run Code Online (Sandbox Code Playgroud)

该应用程序处于发布配置中.

每当我尝试在本地计算机上运行应用程序时,它总是会出错:

The program '[2272] StartupApp.exe' has exited with code -1073741790 (0xc0000022). …
Run Code Online (Sandbox Code Playgroud)

c# c++ python dll uwp

4
推荐指数
1
解决办法
8469
查看次数

标签 统计

c# ×1

c++ ×1

dll ×1

python ×1

uwp ×1