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 / July 2006

Tip: Looking for answers? Try searching our database.

DWORD* in C#

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
GoldenK - 03 Jul 2006 10:39 GMT
Hi,

I have an unmanaged dll 'BeHwAPI.dll', on which I want to call two methods
'GetPortRtsTimerResolution' and 'SetPortRtsTimerResolution' from C#. I have
the following doc.:

BEHWAPI_API BOOL GetPortRtsTimerResolution(HANDLE hComPort,DWORD*
dwMicroSeconds);
BEHWAPI_API BOOL SetPortRtsTimerResolution(HANDLE hComPort,DWORD
dwMicroSeconds);

I have tried the following:
[DllImport("BeHwAPI.dll", EntryPoint="GetPortRtsTimerResolution")]
 internal static extern bool GetPortRtsTimerResolution(IntPtr hComPort, ref
UInt32 microSeconds);
[DllImport("BeHwAPI.dll", EntryPoint="SetPortRtsTimerResolution")]
 internal static extern bool SetPortRtsTimerResolution(IntPtr hComPort,
UInt32 microSeconds);

If I call
bool ok = GetPortRtsTimerResolution((int)comPort, ref rtsRes);

It return true, but the value I retrieve is always 0 - even though I have
just tried to set another value.

My question is do I use the correct datatype and reference for DWORD*?

Thanks in Advance.
Michael C - 05 Jul 2006 01:39 GMT
> My question is do I use the correct datatype and reference for DWORD*?

Yes, although I would use out instead as this allows you to pass in
uninitialized data and change from uint32 to int32 (dword is signed isn't
it?). I'm not sure if the [Out] attribute is required or not. You could also
try the [Out] attrib with ref as well.

[DllImport("BeHwAPI.dll", EntryPoint="GetPortRtsTimerResolution")]
 internal static extern bool GetPortRtsTimerResolution(IntPtr hComPort,
[Out] out
int32  microSeconds);

Michael
Mattias Sjögren - 05 Jul 2006 07:20 GMT
>and change from uint32 to int32 (dword is signed isn't it?).

No it's unsigned.

>I'm not sure if the [Out] attribute is required or not.

Not if you use out.

>You could also try the [Out] attrib with ref as well.

That's effectively the same as using the out keyword.

Mattias

Signature

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

GoldenK - 05 Jul 2006 07:55 GMT
Hi Mattias,

does this mean that you think I'm doing this the right way. Because then I
will talk to the hw vendor.

thanks.

Lars

> >and change from uint32 to int32 (dword is signed isn't it?).
>
[quoted text clipped - 9 lines]
>
> Mattias
Christian Fröschlin - 05 Jul 2006 10:02 GMT
> Hi Mattias,
>
> does this mean that you think I'm doing this the right way. Because then I
> will talk to the hw vendor.

What does BEHWAPI_API resolve to? It might use
a special calling convention like _cdecl.

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.