ctypes 找不到查找 dll 函数

ctypes can't find find dll function

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

Header.h

#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.h

#pragma once

#define DllExport __declspec( dllexport )

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