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
//---- Error is System.OutOfMemoryException
Mattias Sj?gren - 23 Mar 2005 23:58 GMT
>img = new IMG();
>
>dosomething(ref img);
If you're not assigning IMG.release, you may as well change its type
to an IntPtr and see if that helps.
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
shirsoft - 24 Mar 2005 08:50 GMT
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
shireesh