I'm trying to find a way to add code to swig generated functions. I have used typemaps to extend classes, but can't find anything in the documentation about extending specific functions.
Given the following swig interface file:
%module Test
%{
#include "example.h"
%}
%typemap(cscode) Example %{
bool 64bit = SizeOf(typeof(System.IntPtr)) == 8;
static string Path = 64bit ? "/...Path to 64 bit dll.../" :
"/...Path to 32 bit dll.../";
%}
%include "example.h"
I get the following C# code:
public class MyClass : global::System.IDisposable {
...
bool 64bit = SizeOf(typeof(System.IntPtr)) == 8;
static string Path = 64bit ? "/...Path to 64 bit dll.../" :
"/...Path to 32 bit dll.../";
...
public static SomeObject Process(...) { // Function defined in example.h
<- I would like to add some code here.
SomeObject ret = new SomeObject(...);
}
...
}
I would like to add some code to the function Process, this code is a call to SetDllDirectory(Path)
which loads the correct dll depending on the platform type. This needs to happen inside the Process()
call.
Any help is greatly appreciated!
SetDllDirectory()
) during the translation from the preexisting C++ source file. If that is right, then I think you have to rearrange your C++ code to accommodate that injection. EG Creating a stub virtual function call inProcess()
C++ code which you can later override once you are in the C# realm. – Wynn