我寫了一個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」(我不知道如何給每個人授予權限),但是錯誤仍然出現。
模塊是本地的,並且本地調試當前被禁用。你嘗試啓用本機調試嗎? –