Hi, thanks in advance for your time and eventually for your help.
I have to wrap some c functions from a dll creating a C# assembly .
I tried many forums etc etc but i didn't find any help .
Here's the c funtion prototype :
short SessionNew( Session *pSession, SessionNewArgRec *pSessionNewArgRec );
where :
typedef struct _Session * Session ;
struct _Session is not defined anywhere, so i suppose that Session is a int ptr
SessionNewArgRec is a struct which im sure i do a good conversion of .
this is what i've written up to now :
[DllImport( "libxxx30.dll" , SetLastError = true, CallingConvention=CallingConvention.Cdecl)]
public static extern short SessionNew( IntPtr hSession, IntPtr lpSessionNewArg);
i don't think this is right, 'cause either it gives a memory violation exception, or i get an "invalid parameter" error code from the function .
here is the c sample code to help you understand what i have to do :
Session sess = NULL;
SessionNewArgRec args ;
// ... here i fill the SessionNewArgRec structure
SessionNew( &sess, &args );
PLEASE HELP ME IF YOU CAN ... im desperate ..

Help with strange PInvoke conversion
Dhaval-Patel
i mean something like :
IntPtr hSessionPtr = IntPtr.Zero;
api.SessionNew( out hSessionPtr, .... );
sorry but im not a .net guru :P
NeroToxic
RobertFogt
xRuntime
IntPtr hSession = Marshal.AllocHGlobal(2048);
Any luck digging up that 'C' code yet that uses this DLL
aditi shah
IntPtr hSession = IntPtr.Zero;
SessionNewArg args = new SessionNewArg();
// ... i fill the args structure
api.SessionNew( out hSession, args.getPtr() );
// the args.getPtr() simply returns an IntPtr to the marshalld structure
and here is the result :
Excetion : Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at xxx.api.SessionNew( IntPtr& hSession, IntPtr lpSessionNewArg)
here's the message ...
it seems that the function expects something inside hSession ...
ronnie2002c2c
Dylan Smith
struct _Session is not defined anywhere ... im sure of this ... so the code :
typedef struct _Session * Session;
means :
typedef void * Session;
i suppose that this is some kind of a strage way to type-define a general purpose handle ... due to the fact that i really don't know how to "translate" this from c to c#, i'm getting all sort of errors from the function ...
the code :
Session sess = NULL;
SessionNewArgRec args ;
// ... here i fill the SessionNewArgRec structure
SessionNew( &sess, &args );
is the only code you need to make this work in a c/c++ applications ...
Madhu Gandhi