Anybody can give me full C to C# data type mapping table ?

N

news.microsoft.com

ie ,
int WINAPI HWGetPhrase(WORD wCode,LPWORD* pResult);

How can i use it in C# ? When i use DllImport , what data type should i use
for LPWORD* ?


I need FULL data type mapping table . Thanks .
 
N

news.microsoft.com

There are no LPWORD keyword in it , only WINAPI in it , but I need write
code using my own dll .
 
M

Maarten Struys

For this one I would guess you could use the following:

static extern int WINAPI HWGetPhrase(ushort code,ushort[] result);


--
Regards,

Maarten Struys
PTS Software bv
----
 
P

Peter Foot [MVP]

An LPWORD is a pointer to a word. A word is a 2 byte structure so you can
use a UInt16. To pass back the result you should declare the pResult
parameter as a ref UInt16 - the function receives a reference to the
variable (address) which is then populated with the result. You must create
and initialise a UInt16 variable to receive this result. e.g.

[DllImport("filename.dll")]
private static extern int HWGetPhrase(UInt16 wCode, ref UInt16 pResult);

public Uint16 myFunction(UInt16 code)
{

UInt16 myResult = 0;

HWGetPhrase(code, ref myResult);

return myResult;
}

Peter

--
Peter Foot
Windows Embedded MVP

In The Hand
http://www.inthehand.com
Handheld Interactive Reference Guides
 
A

Alex Feinman [MVP]

In fact for functions that return values via pointer it is even better to
declare the parameter as [out] vs [ref]. This allows to avoid compiler error
about using uninitialized variable

private static extern int HWGetPhrase(UInt16 wCode, out UInt16 pResult);


Peter Foot said:
An LPWORD is a pointer to a word. A word is a 2 byte structure so you can
use a UInt16. To pass back the result you should declare the pResult
parameter as a ref UInt16 - the function receives a reference to the
variable (address) which is then populated with the result. You must create
and initialise a UInt16 variable to receive this result. e.g.

[DllImport("filename.dll")]
private static extern int HWGetPhrase(UInt16 wCode, ref UInt16 pResult);

public Uint16 myFunction(UInt16 code)
{

UInt16 myResult = 0;

HWGetPhrase(code, ref myResult);

return myResult;
}

Peter

--
Peter Foot
Windows Embedded MVP

In The Hand
http://www.inthehand.com
Handheld Interactive Reference Guides


news.microsoft.com said:
There are no LPWORD keyword in it , only WINAPI in it , but I need write
code using my own dll .
should
 

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