If I have this method defined in a header file for a 3rd party DLL:
AT_RESULT_CODE ATGetVersion (
int32* piSensorVersion,
int32* piLibMajorVersion,
int32* piLibMinorVersion,
int32* piLibBuildVersion,
int32* piVersionCRC)
and I've defined it like this in my managed code:
[DllImport("atsc63.dll",CharSet=CharSet.Auto)]
public static extern int ATGetVersion (
ref Int32 sensorVer,
ref Int32 major,
ref Int32 minor,
ref Int32 build,
ref Int32 crc );
Is my definition correct? How do I pass null as the first param,
since I can't assign null to an Int32???
Joe
Mattias Sj?gren - 16 Nov 2004 20:08 GMT
>Is my definition correct?
Yes it looks good.
>How do I pass null as the first param,
>since I can't assign null to an Int32???
If you want to pass in null you can change the parameter type to
IntPtr and pass in IntPtr.Zero.
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Heath Stewart [MSFT] - 21 Nov 2004 09:01 GMT
If you declare the parameters as IntPtr, however, do not use ref IntPtr.
IntPtr is already a pointer to an int.
Alternatively, you could declare the parameters as objects (not ref
object, since object is already a reference type) and pass Missing.Value.

Signature
Heath Stewart
Software Design Engineer
Developer Division Sustained Engineering
Microsoft Corporation
Mattias Sj?gren - 26 Nov 2004 21:56 GMT
>Alternatively, you could declare the parameters as objects (not ref
>object, since object is already a reference type) and pass Missing.Value.
I don't think that works for PInvoke. Object parameters gets marshaled
as VARIANTs, which is very different from an int*. You could apply
MarshalAs(UnmanagedType.AsAny), but even then the runtime doesn't
handle Missing.Value as the argument.
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.