Python不会在Windows 11中加载C语言DLL(在Windows 10中加载) 您所在的位置:网站首页 windows加载中 Python不会在Windows 11中加载C语言DLL(在Windows 10中加载)

Python不会在Windows 11中加载C语言DLL(在Windows 10中加载)

2023-03-13 10:21| 来源: 网络整理| 查看: 265

我在Windows 10 Pro版本10.0.19045 Build 19045上运行Python 3.8.5。我有一个应用程序,其中我将部分处理转移到了一个DLL中,该DLL使用Microsoft Visual Studio C++ 2019以C语言编写。我正在加载库DLL并调用其中的函数,没有出现任何问题。我的同事们现在已经开始测试了,他们报告说DLL在Windows 11下“无法加载”。我已经能够用下面的最小应用程序复制该错误:test.py

import ctypes import _ctypes dll = ctypes.WinDLL("./test_dll.dll") dll.RunTest.restype = ctypes.c_int dll.RunTest.argtypes = [ctypes.c_int] print(dll.RunTest(0)) _ctypes.FreeLibrary(dll._handle)

试验h:

#ifndef TEST_H #define TEST_H #if defined(_MSC_VER) && _MSC_VER>=1020 #pragma once #endif #include #include #if !defined(MYDLL) # if defined(TESTDLL_EXPORTS) # define MYDLL extern "C" __declspec(dllexport) # else # define MYDLL extern "C" __declspec(dllimport) # endif #endif #ifdef __cplusplus extern "C" { #endif MYDLL int WINAPI RunTest(int seed); #ifdef __cplusplus } #endif #endif

test.cpp:

#include "pch.h" #include "test.h" MYDLL int WINAPI RunTest(int seed) { return 42; }

这在Windows 10上打印42,在Windows 11上“无法加载”先谢了!



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有