Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Conversion of C code to VB

Posted on 2011-03-15
5
Medium Priority
?
813 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:Dave Hayzen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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:
Dave Hayzen 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:Dave Hayzen
ID: 35178773
Question closed as figured out myself
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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 opening and writing to files in the C programming language.

719 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