pass 2 byte value to DLL from managed code?

M

Monk

Hello,

I have a DLL function that I'm trying to call. I've been successful
with the other calls to this DLL, but am hung up on this one.

Here's the function header from the header file. The source is not
available for the DLL, but they did publish the function header.

CP2101_SetVid(
HANDLE cyHandle,
WORD wVid
);

The documentation says that I should pass a 2 byte value at wVid to
this function. Elsewhere it says that this is an unsigned value. I'm
wondering can someone help me with the following 2 questions.

How do I create a 2 byte value in managed code?
What should my DLLImport statement look like once I've done this? Does
this look correct?

Monk
<DllImport("CP2101")> Friend Shared Function CP2101_SetVid(ByVal
Handle As Int32, <MarshalAs(UnmanagedType.U2)> ByVal VendorID As
Int16) As Int32


Any help or pointer to the right spot in the documentation would be
appreciated.
 
M

Mattias Sjögren

How do I create a 2 byte value in managed code?

You use Short (Int16) or UInt16 (aka UShort in VB Whidbey).

What should my DLLImport statement look like once I've done this? Does
this look correct?

Monk
<DllImport("CP2101")> Friend Shared Function CP2101_SetVid(ByVal
Handle As Int32, <MarshalAs(UnmanagedType.U2)> ByVal VendorID As
Int16) As Int32

Yes it looks correct, but you can skip the MarshalAs attribute if you
want.



Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top