我写了一个C++类库在Visual Studio中只定义调用一些Python的函数:你可以在UWP中的C#代码中使用C++ DLL吗?
#pragma once
#include <Python.h>
extern "C"
__declspec(dllexport)
void python()
{
Py_Initialize();
PyRun_SimpleString("2 + 2");
}
我取得了相同的解决方案,这是一个C#空白通用的应用程序的另一个项目。我试图引用从前面提到的项目生成的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();
}
...
}
}
该应用程序处于发布配置。
每当我试着在我的本机上运行的应用程序,它总是给人一个错误:
The program '[2272] StartupApp.exe' has exited with code -1073741790 (0xc0000022).
Activation of the Windows Store app 'ab6a8ef2-1fa8-4cc7-b7b3-fb7420af7dc3_7dk3a6v9mg4g6!App' failed with error 'The app didn't start'.
所以我的问题是这样的:我可以引用一个C++类库从C#UWP项目?或者UWP应用程序的安全性不允许这么做?
还是因为Python.h?
编辑:
我建立一个DLL项目和一个运行时组件,它包裹着它的项目,现在我有这样的错误:
类型的异常“系统
'System.DllNotFoundException' occurred in StartupApp.exe but was not handled in user code
Additional information: Unable to load DLL 'pathtodll': Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
我添加了一个用户到DLL的对象名称为“Everyone”(我不知道如何给每个人授予权限),但是错误仍然出现。
模块是本地的,并且本地调试当前被禁用。你尝试启用本机调试吗? –