very simple shared dll with ctypes

mclaugb mclaugb at nospm.yahoo.com
Tue Jun 19 07:23:38 EDT 2007


I have created a simple windows small_dll.dll exporting a function that does
a computation using C and C++ classes which i wish to call from Python.  I
have read lots of ctypes documentation but I still dont quite understand how
to call the function.

As a test, I have written a much simpler mathematical function below to try
to get it to work from Python.

I am trying to call this from python by:

>>from ctypes import *

>>print cdll.small_dll.adder(c_double(5.343534),c_double(3.4432))

>>2223968

Can someone give me a few tips to get going!
The DLL declaration is below.



#include<windows.h>

#if defined(_MSC_VER)

#define DLL extern "C" __declspec(dllexport)

#else

#define DLL

#endif


DLL double adder(double a, double b){

double c;

c=a+b;

return c;

}







More information about the Python-list mailing list