[Mono-osx] Beginner - Very Simple P/Invoke Example?
cannyshammy
mike.cann at gmail.com
Sun Jan 3 17:15:37 EST 2010
Hi,
Im new to Mono development tho I have done a fair bit of XNA stuff. For this
current project however I need to catch system-wide input events so I need
some native code for that.
Im trying to get a very simple P/Invoke example working on OSX. My C looks
like:
#include <stdio.h>
void myMethod( int x )
{
printf("my method called: %d\n",x);
}
Which compiles to libXCodeMono.dylib
I have then copied that to my mono project bin dir and tried to use it with
the following code:
using System;
using System.Runtime.InteropServices;
namespace SimpleMacMonoHook
{
public class MacHook
{
[DllImport("libXCodeMono")]
static extern int myMethod (int x);
public MacHook ()
{
myMethod(99);
}
}
}
But it throws me the following error:
Unhandled Exception: System.DllNotFoundException: libXCodeMono.dylib
at (wrapper managed-to-native) SimpleMacMonoHook.MacHook:myMethod (int)
at SimpleMacMonoHook.MacHook..ctor () [0x00006] in
/Volumes/SHARED/Dropbox/Projects/Personal/Live/Inputtie/Mono/SimpleMacMonoHook/SimpleMacMonoHook/MacHook.cs:25
at SimpleMacMonoHook.MainClass.Main (System.String[] args) [0x00000] in
/Volumes/SHARED/Dropbox/Projects/Personal/Live/Inputtie/Mono/SimpleMacMonoHook/SimpleMacMonoHook/Main.cs:22
I have attached my project here:
http://old.nabble.com/file/p27004258/XCodeMono.zip XCodeMono.zip
Anyone got any ideas where im going wrong? Even better can anyone point me
in the direction of some good mac pinvoke resources?
Cheers,
Mike
--
View this message in context: http://old.nabble.com/Beginner---Very-Simple-P-Invoke-Example--tp27004258p27004258.html
Sent from the Mono - OSX mailing list archive at Nabble.com.
More information about the Mono-osx
mailing list