vis781
Well-known member
Ok, so i've been playing around with some of the more obscure functions in the win32 api, and i have to say that I am startingto lose heart with vb.net. Bearing in mind that both languages are supposed to be equivalent but the 'same' routine can produce such drasticaly different results when comapred to c# and becuase i have run the same function s from both managed c++ and unmanaged c++ unfortunately the c# version of the code returns the correct value!!!! Here it is. I would appreciate anyone telling me why on earth these two functions should return different values. It's late, maybe i've missed something obvious if i have then I will be a happy man. Try it if you dare....
c# version
vb.net version
On my machine they return two different values for a win32 color, doesn't matter what the latter two values are. How could this be????
Another example trying to mimic the RGB macro from c++....
c# version performs perfectly, whereas the vb.net version....
Doesn't!!! Same Signature, same conversion... different result. If anyone could explain this to me i'd be grateful. I don't think i've missed anything. I just dont see why it shouldn't work.
The only thing I can think of is that c# allows a bitwise Or as well as a logical Or
c# version
VB.NET:
public static int MulDiv(int number, int numerator, int denominator)
{
float num = (number * numerator) / denominator;
return (int)Math.Round((double)num);
}
vb.net version
VB.NET:
Public Shared Function MulDiv(ByVal number As Integer, ByVal numerator As Integer, ByVal denominator As Integer) As Integer
Dim num As Single = ((number * numerator) / denominator)
Return CInt(Math.Round(CDbl(num)))
End Function
On my machine they return two different values for a win32 color, doesn't matter what the latter two values are. How could this be????
Another example trying to mimic the RGB macro from c++....
VB.NET:
public static int RGB(int r, int g, int b)
{
return ((((byte)r) | (((byte)g) << 8)) | (((byte)b) << 0x10));
}
c# version performs perfectly, whereas the vb.net version....
VB.NET:
Public Shared Function RGB(ByVal r As Integer, ByVal g As Integer, ByVal b As Integer) As Integer
Return (((CByte(r)) Or ((CByte(g)) << 8)) Or ((CByte(b)) << &H10))
End Function
Doesn't!!! Same Signature, same conversion... different result. If anyone could explain this to me i'd be grateful. I don't think i've missed anything. I just dont see why it shouldn't work.
The only thing I can think of is that c# allows a bitwise Or as well as a logical Or