2

I am reading some VB6 to convert to C#. What does this line mean? Is 0& equivalent to IntPtr.Zero?

//'Get a Device context
hdc = GetDC(0&)

This value is used to pinvoke, so I'm not sure IntPtr.Zero makes sense since we need to be selecting some object.

OldFont = SelectObject(hdc, ObjFont)

Note, ObjFont is populated via

//'Get the Window's font
ObjFont = SendMessage(hwnd, WM_GETFONT, 0, 0&)//there's that mysterious 0& agaain.
P.Brian.Mackey
  • 43,228
  • 68
  • 238
  • 348

4 Answers4

6

It is a (VB6) type declaration character. Have a look at this question for more details on these.

In your example VB6 code it is forcing 0 to be a Long (4 bytes) as it would otherwise be an Integer (2 bytes)

It is the same as doing this long hand approach again VB6 code:

Dim lParam as Long
lParam = 0
ObjFont = SendMessage(hwnd, WM_GETFONT, 0, lParam)
Community
  • 1
  • 1
Matt Wilko
  • 26,994
  • 10
  • 93
  • 143
6

In your specific example, yes, it's equivalent to IntPtr.Zero in C#.

It's the "null handle value" for VB6, that is used by GetDC to return the device context for the entire screen.

ken2k
  • 48,145
  • 10
  • 116
  • 176
3

That's equivalent to passing NULL to GetDC() which instructs the function to return the hDC for the entire screen, so IntPtr.Zero is equivalent.

Alex K.
  • 171,639
  • 30
  • 264
  • 288
0

It's the same as Clng(0) :) As the guy below said;D

Nickon
  • 9,652
  • 12
  • 64
  • 119