Interop Problem?

OC_CarlOC_Carl USMember ✭✭

I am trying to call into a native C routine to get back a unsigned long / ulong value.

My C# code is:

class MainClass
{
    [DllImport("mylib", EntryPoint = "getsz")]
    public static extern ulong Bug();

    public static void Main (string [] args)
    {
        Console.WriteLine ("Return value from call = " + Bug());
        Console.WriteLine ("Return value from call = " + Bug());
        Console.WriteLine ("Return value from call = " + Bug());
    }
}

mylib.c is simply:

            unsigned long getsz()
            {
              return 3;
            }

I compiled & linked using these commands:
$ clang -arch i386 -fpic -c mylib.c -o mylib.o
$ clang -arch i386 -dynamiclib mylib.o -o libmylib.dylib

The result from "Start Debugging" is:
Return value from call = 9049715685759909891
Return value from call = 3
Return value from call = 3

The result "Start Without Debugging" is:
Return value from call = 8837490012950888451
Return value from call = 8839758545957158915
Return value from call = 8839758545957158915

Xamarin Studio Community
Version 6.0.2 (build 73)
Xamarin.Mac
Version: 2.8.2.22 (Xamarin Studio Community)
Operating System
Mac OS X 10.11.5

Is this a problem or am I missing something?

Sign In or Register to comment.