0

I have a third party DLL (no header file) written in C++ and I am able to get the function prototype information from the developer, but it is proprietary and he will not provide the source.

I've gone through the SWIG tutorial but I could not find anywhere specifying how to use SWIG to access any functions with only the DLL file. Everything on the tutorial shows that I need to have the header so SWIG knows what the function prototypes look like.

Is SWIG the right route to use in this case? I am trying to load this DLL in Python so I can utilize a function. From all of my research, it looks like Python's ctypes does not work with C++ DLL files and I am trying to find the best route to follow to do this. Boost.python seems to require changing the underlying C++ code to make it work with Python.

To sum up, is there a way to use SWIG when I know the function prototype but do not have the header file or source code?

chrcoe
  • 412
  • 4
  • 13
  • it turns out we are able to get the header file so I should be able to get it working right with SWIG. – chrcoe Mar 14 '14 at 20:53

3 Answers3

2

Even without a header file, if you have the prototype, you can make a header file yourself, or just enter the prototype directly in the SWIG interface file.

For example, if the prototype is:

int sum(const std::vector<int>& vint);

The SWIG interface would be:

%module example
%{
    #include <vector>
%}
%include <std_vector.i>                # SWIG support
%template() std::vector<int>;          # Generate code to support template instance.

int sum(const std::vector<int>& vint); # Generate wrapper for function.
Mark Tolonen
  • 166,664
  • 26
  • 169
  • 251
  • This is what I ended up doing. Everyone I spoke to before you said it is impossible without the header file and I didn't know any better. I gave it a shot and ended up getting that to work, thanks! – chrcoe Mar 24 '14 at 15:15
0

To use a library (static or dynamic), you need headers and library file .a, .lib...

Its true for c++ and I think its the same for Python

hrkz
  • 378
  • 3
  • 14
  • I guess I came to the conclusion that SWIG or boost might do the trick because of various questions on here about using a C library with just the DLL file via Python's ctypes module function `cdll.LoadLibrary('file.dll')` [python ctypes](http://docs.python.org/2/library/ctypes.html) similar to this question also: http://stackoverflow.com/questions/252417/how-can-i-use-a-dll-from-python – chrcoe Mar 13 '14 at 13:08
0

SWIG cannot be used without the header files. Your only option is a lib like ctypes. If you find ctypes doesn't do it for you and you can't find alternative then post a question with why ctypes not useable in your case.

Oliver
  • 27,510
  • 9
  • 72
  • 103