Reputation: 83
I am currently creating my first swig project. I have some c++ code, where i am using 1 of the classes functions in my c# UI. I have created a .i file that looks something like this:
%module mymodule
%{
#include "Simulation.h"
%}
/*****************************************************************************
* SOME DEFINITIONS *
*****************************************************************************/
#define EXAMPLE_DEFINITION 'a'
#define EXAMPLE_DEFINITION_2 'x'
class Simulation
{
public:
// BUNCH OF FUNCTIONS
static unsigned int getTick();
static void tick();
// BUNCH MORE FUNCTIONS
private:
// A BUNCH MORE THINGS
};
I added the cs files using:
swig -c++ -csharp -outdir UI -o cpp/simulation_wrap.cpp Simulation.i
It produces several files, which i add to my c# project. in my code if i add the lines:
Simulation.getTick();
or
Simulation.tick();
I get no compile errors, but the following run time error:
The type initializer for 'mymodulePINVOKE' threw an exception.
have I missed out any steps? I have tried searching for this but haven't managed to get any success.
(Perhaps it is important to note that i have tried compiling the c++ as a dll and a lib).
Thanks in advance
Upvotes: 1
Views: 777
Reputation: 31
What worked for me was to:
Go to Build->Configuration Manager. For the C# project change AnyCpu to x86 and rebuild.
Upvotes: 3