
Signature
// Alessandro Angeli
// MVP :: Digital Media
// a dot angeli at psynet dot net
> What about the following?
>
[quoted text clipped - 7 lines]
> [return: MarshalAs(UnmanagedType.Interface)]
> public static extern object FuncFromCDll();
I was simplifying the c function in my question since I thought the
rest of the signature would unnecessarily complicate the question that
I have. Maybe I need to provide more information. The signature
actually is more like below:
HRESULT __stdcall FuncFromCDll(ISomeInterfaceCallback* pCallBack, void*
pUserData, ISomeInterface** ppISomeInterface, int reserved);
In C, I could make this call as follows and it works:
ISomeInterface* someInterface = 0;
CreateInstance(0, (void *) 0, &someInterface , 0);
I was trying to use the following:
[DllImport("somedll.DLL", EntryPoint="FuncFromCDll",
ExactSpelling= true,
CallingConvention=CallingConvention.StdCall)]
public static extern object FuncFromCDll(
IntPtr pISomeInterfaceCallback,
IntPtr pUserData,
ref IntPtr ppISomeInterface,
int lReserved);
I was calling this as below:
IntPtr pISomeInterfaceCallback = IntPtr.Zero;
IntPtr pUserData = IntPtr.Zero;
IntPtr myIntPtr = IntPtr.Zero;
FuncFromCDll(pISomeInterfaceCallback, pUserData, ref myIntPtr, 0);
object myObject = Marshal.GetObjectForIUnknown(myIntPtr);
Would I still be able to define the P/Invoke call similar to what you
described above for this case?
i.e.
[DllImport("somedll.DLL", EntryPoint="FuncFromCDll",
ExactSpelling= false, PreserveSig=false,
CharSet=CharSet.Ansi,
CallingConvention=CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.Interface)]
public static extern object FuncFromCDll(
IntPtr pISomeInterfaceCallback,
IntPtr pUserData,
//??removed ppISomeInterface since it is returned??
int lReserved);
If the above P/Invoke is a valid one, then I have tried it and I got an
"Object reference not set to an instance of an object" exception.
Thanks for your help!
Nauman
Alessandro Angeli [MVP::DigitalMedia] - 12 Jan 2005 19:08 GMT
> Would I still be able to define the P/Invoke call similar
> to what you described above for this case?
I haven't yet found out what attribute defines a retval
which is not the last one.
I tried this in a test program and it works:
[DllImport("somedll.dll"
,EntryPoint="FuncFromCDll"
,ExactSpelling=true
,PreserveSig=true
,CharSet=CharSet.Ansi
,CallingConvention=CallingConvention.StdCall
)]
public static extern int FuncFromCDll(
[MarshalAs(UnmanagedType.Interface)]
object pCallBack,
IntPtr pUserData,
[MarshalAs(UnmanagedType.Interface)]
out object ppISomeInterface,
int reserved
);
object pISomeInterface;
int hr = FuncFromCDll
(null,IntPtr.Zero,out pISomeInterface,0);

Signature
// Alessandro Angeli
// MVP :: Digital Media
// a dot angeli at psynet dot net
Alessandro Angeli [MVP::DigitalMedia] - 12 Jan 2005 19:28 GMT
> I haven't yet found out what attribute defines a retval
> which is not the last one.
Well, I found the answer: the retval *must* be the last
param.

Signature
// Alessandro Angeli
// MVP :: Digital Media
// a dot angeli at psynet dot net