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?
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.
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
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.