Solved

Conversion of C code to VB

Posted on 2011-03-15
5
791 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

867 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

22 Experts available now in Live!

Get 1:1 Help Now