Link to home
Start Free TrialLog in
Avatar of Dave Hayzen
Dave HayzenFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Conversion of C code to VB

Can anybody help convert the following into vb6 or vb.NET code please?

I am specifically struggling with the DWORD conversions.


A2.8 Mifare Emulation Mode (OMNIKEY Proprietary API)
With the following code-snippet the Mifare Emulation Mode can switched on and off.

DWORD dwActiveProtocol;
DWORD dwControlFlag;
BYTE InBuffer[16];
BYTE OutBuffer[16];
DWORD dwInBufferSize ;
DWORD dwOutBufferSize;
DWORD dwBytesReturned;
DWORD *Mask = (DWORD *)InBuffer;
DWORD *Value = (DWORD *)InBuffer+1;
DWORD dwControlCode = CM_IOCTL_SET_RFID_CONTROL_FLAGS;
memset(InBuffer, 0x00, sizeof(InBuffer));
memset(OutBuffer, 0x00, sizeof(OutBuffer));
*Mask = 0x00000004;
*Value = dwControlFlag & *Mask;
dwInBufferSize = 8;
dwOutBufferSize = 0;
dwBytesReturned = 0;
SCard_Status = SCardControl(hCard,
dwControlCode,
(LPCVOID)InBuffer,
dwInBufferSize,
(LPVOID)OutBuffer,
dwOutBufferSize,
&dwBytesReturned);
if (SCard_Status == SCARD_S_SUCCESS)
{
if(dwControlFlag)
sprintf(szText,"Mifare\t");
else
sprintf(szText,"T=CL\t");
}
else
{
sprintf(szText,"IO Cntrol error\r");
}
// The card is disconnected after changing the Mifare emulation mode
do
{
sReaderState.szReader = szReaderName;
sReaderState.dwCurrentState = SCARD_STATE_EMPTY;
sReaderState.dwEventState = SCARD_STATE_EMPTY;
SCardGetStatusChange(hContext,50,&sReaderState,1);
}
while((sReaderState.dwEventState & SCARD_STATE_PRESENT) == 0);
Avatar of ramkihardy
ramkihardy

Long in VB is 64 bits (maps to System.Int64) – also,
VB does know unsigned data types (again: VB.NET).A Long in VB.NET is a 64-bit value.  

you easliy find out :
the datatype used insted of DWORD...by using this..
Dim value As Object = Registry.GetValue("HKEY_CURRENT_USER\Console", "FontSize", -1)
Console.WriteLine(value.GetType().FullName)
In the case of a REG_DWORD value this will print "System.Int32", which would be an Integer in VB.NET.
 
Avatar of hes
Have a look at Sharp Developer. It can convert back and forth from C# to VB  .net

http://www.icsharpcode.net/opensource/sd/
It should be something like this:

Dim dwActiveProtocol as UInt32
Dim dwControlFlag as UInt32
Dim InBuffer() as Byte = new Byte(){}
Dim InBufferWriter as BinaryWriter = New BinaryWriter(New MemoryStream(InBuffer))
Dim OutBuffer() as Byte = New Byte(16){}
Dim dwInBufferSize as UInt32
Dim dwOutBufferSize as UInt32
Dim dwBytesReturned as UInt32
Dim Mask as UInt32
Dim Value as UInt32
Dim dwControlCode as UInt32 = CM_IOCTL_SET_RFID_CONTROL_FLAGS
Mask = &H00000004
Value = dwControlFlag And Mask
BinaryWriter.Write(Mask)
BinaryWriter.Write(Value)
dwInBufferSize = 8
dwOutBufferSize = 0
dwBytesReturned = 0
SCard_Status = SCardControl(hCard, _
			dwControlCode, _
			InBuffer, _
			dwInBufferSize, _
			OutBuffer, _
			dwOutBufferSize, _
			dwBytesReturned)
if (SCard_Status = SCARD_S_SUCCESS)
{
   	if (dwControlFlag)
		szText = "Mifare" & vbTab
	else
		szText = "T=CL" & vbTab
}
else
{
	szText = "IO Cntrol error" & vbCr
}

'// The card is disconnected after changing the Mifare emulation mode
do
{
	sReaderState.szReader = szReaderName
	sReaderState.dwCurrentState = SCARD_STATE_EMPTY
	sReaderState.dwEventState = SCARD_STATE_EMPTY
	SCardGetStatusChange(hContext,50,sReaderState,1)
}
while((sReaderState.dwEventState And SCARD_STATE_PRESENT) = 0)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Dave Hayzen
Dave Hayzen
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dave Hayzen

ASKER

Question closed as figured out myself