Hi Mattias,

Many thanks for your prompt response :-) The declarations for the C functions involved 
are:

// Callback function pointer def
typedef unsigned (__cdecl *ioCallbackPtr)(unsigned char *buffer, unsigned long count, 
unsigned long filePtr);

// Declaration for function I call from C#
void *tpFunction(void *, ioCallbackPtr, unsigned long);

// Declaration for fread() - called from the callback
size_t fread(void *buffer, size_t size, size_t count, FILE *stream);

I'll make the changes you suggest, i.e. setting CallingConvention.Cdecl in the fread() 
DllImport attribute and attempt to verify the version of the C runtime that's being 
used (although I don't believe the initial function actually uses the FILE pointer).

If the initial function expects the callback to be called with the cdecl calling 
convention, can that be specified in the C# declaration for the callback?

Best regards,

Ron

----- Original Message -----
From: Mattias Sjögren <[EMAIL PROTECTED]>
Date: Tuesday, January 27, 2004 2:01 pm
Subject: Re: [ADVANCED-DOTNET] Callbacks from unmanaged code

> Ron,
> 
> Can you post the C function declarations? That would make it 
> easier to help 
> you find errors. Some things you should keep in mind
> 
> - The CRT functions use the cdecl calling conventions. You should 
> set 
> CallingConvention.Cdecl in the fread() DllImport attribute.
> 
> - If the callback function is supposed to use the cdecl convention 
> too, you 
> have to fix that (which is non trivial). Delegates are marshaled 
> to stdcall 
> function pointers by default.
> 
> - If the third party library uses the FILE pointer internally, you 
> have to 
> verify that you're using the same C runtime version.
> 
> 
> Mattias
> 
> -- 
> Mattias Sjögren
> [EMAIL PROTECTED]
> 
> ===================================
> This list is hosted by DevelopMentor®  http://www.develop.com
> Some .NET courses you may be interested in:
> 
> NEW! Guerrilla ASP.NET, 26 Jan 2004, in Los Angeles
> http://www.develop.com/courses/gaspdotnetls
> 
> View archives and manage your subscription(s) at 
> http://discuss.develop.com

===================================
This list is hosted by DevelopMentor®  http://www.develop.com
Some .NET courses you may be interested in:

NEW! Guerrilla ASP.NET, 26 Jan 2004, in Los Angeles
http://www.develop.com/courses/gaspdotnetls

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to