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

  • Thread starter Thread starter news.microsoft.com
  • Start date Start date
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 .
 
There are no LPWORD keyword in it , only WINAPI in it , but I need write
code using my own dll .
 
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
----
 
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
 
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
 
Back
Top