Convert VB to C#, Operator "Not"

G

Guest

Hi all,

I try to convert VB codes to C#. I got this error "Operator '!'cannot be
applied to operand of type 'long'".

Any ideas? Why doesn't "Not SYNCHRONIZE" equivalent to "!SYNCHRONIZE"?

Thanks,

VB:

Public Const SYNCHRONIZE = &H100000
Public Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or
KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY
Or KEY_CREATE_LINK) And (Not SYNCHRONIZE))

C#:
public const long SYNCHRONIZE = 0x100000;
public const bool KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL
| KEY_QUERY_VALUE
| KEY_SET_VALUE
| KEY_CREATE_SUB_KEY
| KEY_ENUMERATE_SUB_KEYS
| KEY_NOTIFY
| KEY_CREATE_LINK)
& !SYNCHRONIZE);
 
M

Marc Gravell

Why doesn't... <snip>
Because it means something different?

! is the boolean negation operator
~ is the bitwise complement operator

Try ~SYNCHRONIZE instead

Marc
 
G

Guest

I have tried ~SYNCHRONIZE but I got this error "Cannot implicitly convert
type 'long' to 'bool'".
 
M

Marc Gravell

That is the final assignment step; depending on what your code is trying to
do (I must admit, I'm not 100% sure from the sample alone) then you probably
need to add " != 0" or " == {the bytes you are looking for}" - the latter
may require shoving the value into a variable first.

Basically, it comes down to integer / long values deliberately not being
"true" or "false"; if VB long 0 means "false", then you probably just need
to add the != 0 explicitely.

Marc
 
T

Tomislav Tustonic

ano said:
I have tried ~SYNCHRONIZE but I got this error "Cannot implicitly convert
type 'long' to 'bool'".

Constant KEY_ALL_ACCESS is not boolean, it is obviously a long int,
since SYNCHRONIZE is declared long. Also, when you use bitwise operators
between values, the result is not a boolean, it's an int (or long, or
uint, or something).

HTH, Tom.
 

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