Solved

Conversion of C code to VB

Posted on 2011-03-15
5
788 Views
Last Modified: 2012-05-11
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);
0
Comment
Question by:dhayzen
5 Comments
 
LVL 2

Expert Comment

by:ramkihardy
ID: 35137408
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.
 
0
 
LVL 20

Expert Comment

by:hes
ID: 35138718
Have a look at Sharp Developer. It can convert back and forth from C# to VB  .net

http://www.icsharpcode.net/opensource/sd/
0
 
LVL 23

Expert Comment

by:wdosanjos
ID: 35144177
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

0
 
LVL 1

Accepted Solution

by:
dhayzen earned 0 total points
ID: 35148505

Thanks for your comments folks... I managed to get to where I needed to be in the end but unfortunately not by using any of your comments.

I ended up writing what I needed in C++.

Cheers.
0
 
LVL 1

Author Closing Comment

by:dhayzen
ID: 35178773
Question closed as figured out myself
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now