Solved

Conversion of C code to VB

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.NET - Why is accordion not working? 3 44
Problem to copy file 14 43
Return array 3 19
Create a button class for use in all vb.net apps 5 13
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The goal of this video is to provide viewers with basic examples to understand opening and writing to files 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.

685 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