python - ctypes找不到find dll函数

标签 python c++ dll ctypes

我是C++的完全入门者,一直在尝试通过ctypes使用DLL从Python访问C++函数。
运行代码时,我总是收到错误AttributeError: function 'my_function' not found

header

#pragma once

int my_function(void);

Source.cpp
#include "Header.h"

int my_function(void)
{
    return(17); //test
}

ctypesTest.py
import ctypes

if __name__ == "__main__":

    mydll = ctypes.CDLL("MyDLL.dll")

    print(mydll.my_function())

每次我运行Python脚本时,都会出现属性错误。

我只需要预期功能中的值。

最佳答案

@Mikel Rychliski回答了我的问题。

header

#pragma once

#define DllExport __declspec( dllexport )

extern "C"
{
    __declspec(dllexport) int my_function(void);
}

关于python - ctypes找不到find dll函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61263597/

相关文章:

c++ - 函数名称修改。 _cdecl约定

使用其他 dll/lib 中定义的函数编译 dll

windows - 在哪里可以找到 Windows(XP、Vista、7 等)上可用的默认 dll 文件列表?

python - pyparsing中Word的非贪婪匹配?

Python 检查几个 if 条件(查找并用数字替换单词)

c++ - LD_LIBRARY_PATH 不包含导出路径

c++ - 如何继承#include 类?

python - 在pycharm中运行pyspark程序

python - Mongo 知道什么是元组吗?

c++ - 堆栈与缓存友好分配器