Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / November 2004

Tip: Looking for answers? Try searching our database.

PInvoke int32*

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Joe Franklin - 16 Nov 2004 19:33 GMT
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.