problems with generation of c# wrapper for c++ function with function ptr argument
Carlos Frederico Biscaya <[email protected]>
| Newsgroups | gmane.comp.programming.swig |
|---|---|
| Message-ID | <CANWOLaahSod9c3UdoeAcUu6++T6sAmPpXoscpG=_UqFRqLqhOA@mail.gmail.com> |
Hi guys, I've started using swig a few months ago and after a few hickups had my first functioning c# wrapper. Now I need to create a wrapper in C# that wrapps a C++ function that takes a function ptr argument. I used a typedef for the function ptr type and the swig macro cs_callback that I found while researching how to get this done. Unfortunatelly I seem to be stuck now. AFAIK one of two things should be happening, which aren't. 1) the delegate corresponding to my typedef for my function ptr is not generated anywhere typedef void (_stdcall *infobarObserverFunc)(InfoBarData*); 2) If I try using a typemap for inserting the delegate member into the generated class, nothing happens. I seem to be way out of my depth here and hope, someone can provide me with some insight as to what is going wrong. I've attached a minimal example that reproducibly gives me headaches and the swig project file needed. In my development environment I am using swig 4.0.1. I've tried using -E to see whether something suspicious show up after preprocessing. Best regards and thank you for your time, Fred _______________________________________________ Swig-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/swig-user
UiData.h
(text/plain, 80 B)
#pragma once
extern "C" {
struct UiData
{
double temperature;
};
}
UiDataProvider.h
(text/plain, 366 B)
#pragma once
#include "UiData.h"
typedef void (_stdcall *uiDataObserverFunc)(InfoBarData*);
#ifdef SYSTEMUI_EXPORTS
#define SYSTEMUI_API __declspec(dllexport)
#else
#define SYSTEMUI_API __declspec(dllimport)
#endif
extern "C" {
SYSTEMUI_API void UI_Init();
SYSTEMUI_API void UI_RegisterObserver(uiDataObserverFunc callbackFunc);
}
UiModule_cs.i
(text/plain, 1.3 KB)
#define SYSTEMUI_EXPORTS
%module UiWrapper
%define %cs_callback(TYPE, CSTYPE)
%typemap(ctype) TYPE, TYPE& "void*"
%typemap(in) TYPE %{ $1 = ($1_type)$input; %}
%typemap(in) TYPE& %{ $1 = ($1_type)&$input; %}
%typemap(imtype, out="IntPtr") TYPE, TYPE& "CSTYPE"
%typemap(cstype, out="IntPtr") TYPE, TYPE& "CSTYPE"
%typemap(csin) TYPE, TYPE& "$csinput"
%enddef
%typemap(ctype) enum SWIGTYPE * "int *"
%typemap(imtype) enum SWIGTYPE * "out int"
%typemap(cstype) enum SWIGTYPE * "out $*csclassname"
%typemap(csin,
pre=" int temp_$csinput = 0;",
post=" $csinput = ($*csclassname)temp_$csinput;"
) enum SWIGTYPE *
"out temp_$csinput"
%typemap(in) enum SWIGTYPE *
%{ $1 = ($1_ltype)$input; %}
%apply enum SWIGTYPE * {enum SWIGTYPE * const}
%rename("%(strip:[UI_])s") "";
%cs_callback(uiDataObserverFunc, cppUiDataObserverCallback)
%typemap(cscode) UiWrapper %{
[UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
public delegate void cppUiDataObserverCallback(UiData* uiDataUpdate);
%}
%{
#include "UiData.h"
#include "UiDataProvider.h"
%}
// these headers have to come before anything else - otherwise syntax error(1) will be thrown
%include <windows.i>
%include <carrays.i>
%include <cpointer.i>
%include "UiData.h"
%include "UiDataProvider.h"