Groups | Blog | Home
all groups > dotnet interop > march 2005 >

dotnet interop : function pointer


Mattias Sjögren
3/23/2005 12:00:00 AM
[quoted text, click to view]

If you're not assigning IMG.release, you may as well change its type
to an IntPtr and see if that helps.



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
shirsoft NO[at]SPAM gmail.com
3/23/2005 2:06:50 AM
I have a struct in C with a function ptr in a dll called Image.dll:
The functionptr is initialized and called in the C-code
The application completes the above operation and then terminates with
an exception of System.OutOfMemoryException


//------------C-Code---------------//
typedef struct _IMG
{
char **ptr;
void (*release)();
}IMG;

void releaseimg()
{
printf("Iam over here");
}

void dosomething(IMG* img)
{
img->release = releaseimg();
img->release();
}




//------------C#-Code---------------//
public delegate void releasefunc();

[StructLayout(LayoutKind.Sequential, Pack=1)]
unsafe public struct IMG
{
public char ** ptr;
public releasefunc release;
};


[DllImport("Image",EntryPoint = "DoSomething",ExactSpelling =
true,CharSet = CharSet.Ansi,CallingConvention =
CallingConvention.Cdecl)]
public static extern void dosomething(ref IMG);

img = new IMG();

dosomething(ref img);

//----Apps crash here after completing the function
shirsoft NO[at]SPAM gmail.com
3/23/2005 11:50:02 PM
thanks mattias,
the program now works like a gem as my c# code never requires to call
the function pointer itself.
btw do u have ne guess how to make it work incase the the c# code
requires calling the func ptr?

thanks
AddThis Social Bookmark Button