P.Brian.Mackey
P.Brian.Mackey

Reputation: 44275

Convert variable values from VB6 to C# in order to work with Win32

I have a series of values from some VB6 code I found online. I need this code converted to C#. I have no idea how to read VB6. How can I convert this VB6 to the equivalent C#?

Private Const EM_GETRECT = &HB2;
Private Const EM_SETRECT = &HB3
Private Const EM_SCROLLCARET = &HB7

Private Const ES_AUTOHSCROLL = &H80&
Private Const ES_AUTOVSCROLL = &H40&
Private Const ES_CENTER = &H1&

Judging by one signature

[DllImport("coredll.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);

that takes these types of variables (as the Msg param), I believe these should be of the form

const int EM_GETRECT =

I don't know how to change the &HB2 to an int. I think it'll be 0x???, but how do I convert this little &HB2 to hex?

Upvotes: 1

Views: 585

Answers (2)

Steve
Steve

Reputation: 216293

The syntax to express an hexdecimal value in C# is simply 0x followed by the hex representation of the number. (And this representation is the same in VB6 and C#) so you write

private const int EM_GETRECT = 0xB2;
Console.WriteLine(EM_GETRECT);

prints out 178 decimal.

The last three values (with the & suffix) are VB variables of long datatype.
In C# the datatype int is the same as VB long. You could still use a C# integer

private const int ES_CENTER = 0x1; 
Console.WriteLine(ES_CENTER);

prints 1 as expected

Upvotes: 4

Vaughan Hilts
Vaughan Hilts

Reputation: 2879

It's just indicating the number is read out in long integer, formatted as hex. (after the H)

You can just use these values if you want:

const int EM_GETRECT = 0xB2;
const int EM_SETRECT = 0xB3;
const int EM_SCROLLCARET = 0xB7;

const int ES_AUTOHSCROLL = 0x80;
const int ES_AUTOVSCROLL = 0x40;
const int ES_CENTER = 0x1;

Upvotes: 3

Related Questions