Reputation: 53
I'm a complete beginner at C++ and have been trying to access a C++ function from Python using a DLL through ctypes.
I always get the error AttributeError: function 'my_function' not found
when running my code.
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())
Every time I run the Python script I get the attribute error.
I only need values out of my intended function.
Upvotes: 1
Views: 1738
Reputation: 53
@Mikel Rychliski answered my question.
Header.h
#pragma once
#define DllExport __declspec( dllexport )
extern "C"
{
__declspec(dllexport) int my_function(void);
}
Upvotes: 2