logo       

Re: Wrapping __declspec(dllimport) and __stdcall: msg#00180

programming.swig

Subject: Re: Wrapping __declspec(dllimport) and __stdcall

Gary Nissen wrote:

I have an external Windows DLL that I have to wrap that has declarations as
such:

__declspec(dllimport) void __stdcall foo(char *)

I cannot find a way to properly handle this sitation. Here is what I've tried:


1) If I include my header in my wrapper.i file as follows then I receive syntax
errors from SWIG

%{
#include "sample.h"
%}

%include "sample.h";


2) If I include my header in my wrapper as follows then I receive "redefinition;
different type modifiers" on compile.

%{
#include "sample.h"
%}

extern void foo(char *);


So how can I have external declarations that pass SWIG's syntax check but also
generate the proper C wrapper code. The issue as I see it it that my #2 above
will generate declarations that are already defined in the #include and don't
match the code.

Number 2) will work. SWIG doesn't need to know about calling conventions, whether or not the function is in a DLL and other stuff like that.

Most people do something like this:

// importexport.h
#define DLLIMPORT __declspec(dllimport)

// sample.h file
#include "importexport.h"
DLLIMPORT void __stdcall foo(char *);

This allows you to change DLLIMPORT for import or export the function. Also it is very handy for SWIG (which doesn't support this non-ISO feature) as you can #define it away:

%{
#include "sample.h"
%}

#define DLLIMPORT
#define __stdcall
%include "sample.h"

William
_______________________________________________
Swig maillist - Swig@xxxxxxxxxxxxxxx
http://mailman.cs.uchicago.edu/mailman/listinfo/swig



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise