I have the following function from a c++ header file:
__int16 __stdcall s_em4305_login (HANDLE m_hUSB, int DataRate, UCHAR * password);
When I run the VB equavelent:
Private Declare Function RF_EM4305_Login Lib "SRF32.dll" Alias "s_em4305_login" (ByVal handle As Long, ByVal DataRate As Long, ByRef bytes As Byte) As Integer
I get -1100 back as a value
When I run the c# equavilent:
[DllImport("SRF32.dll", EntryPoint = "s_em4305_login")]
private static extern ushort RF_EM4305_Login(IntPtr handle, int DataRate,byte[] password);
I get a different value. The 3rd paramater is most likely declared incorrectly. Can someone please assist in converting the c++ declaration to c#
Update
I have added some additional declarations
private static extern ushort RF_EM4305_Login(IntPtr handle, int DataRate,IntPtr password);
private static extern ushort RF_EM4305_Login(IntPtr handle, int DataRate,ref byte[] password);
With all 3 c# declarations I get the value "64436" returned.
System.Int16
akaShort
.Integer
was 16 bit back in Classic VB, but not in VB.NET. Similarly, second parameter should beSystem.Int32
akaInteger
.Long
was 32 bits in Classic VB, but that too changed in VB.NET. And the first parameter has problems, and should useSystem.IntPtr
as does the C# declaration. Different results between VB.NET and C# do not imply your C# declaration is in error... on the contrary it appears the C# declaration is correct and the VB.NET call is erroneous. – Ben VoigtSystem
namespace, which explicitly describe the size. – Ben Voigtstring
along withCharSet.Ansi
would be easier to use, butbyte[]
is not incorrect. – Ben VoigtSystem.Int16
(orshort
) instead ofushort
for the return type in C#. I thought you meant the return value was actually different, not just the same bit pattern treated unsigned... – Ben Voigtint
and 32-bitlong
. – Ben Voigt