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.