By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,417 Members | 1,263 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,417 IT Pros & Developers. It's quick & easy.

C# to VB.net conversion: byte pointers etc

P: 2
Hello there,

I need to convert the following code from C# to Vb.net (it's part of an EMV API).

Expand|Select|Wrap|Line Numbers
  1. unsafe public uint InputPIN(ref byte pPinNum)
  2.         {
  3.  
  4.             MessageBox.Show("Input Password and Push Enter !");
  5.  
  6.             Event_EndOfPinInput.Reset();
  7.             Event_EndOfPinInput.WaitOne();
  8.  
  9.             if (txtPassword.InvokeRequired)
  10.             {
  11.                 string  strPassword = Invoke(new GetPasswordTextCallback(GetPasswordText), new object[] { }).ToString();
  12.                 byte[] byPassword = StrToByteArray(strPassword);
  13.                 fixed (byte* _pPinNum = &pPinNum)
  14.                 {
  15.                     byte* ps = _pPinNum;
  16.                     for (int i = 0; i < 4; i++)
  17.                         *(ps + i) = byPassword[i];
  18.                 }
  19.  
  20.             }
  21.             return 1;
  22.         }
How do I go about converting the 'fixed' block of code. AFAIK VB.net doesn't have byte pointers etc. I think I need Marshal.Copy but guidance would be appreciated.

Expand|Select|Wrap|Line Numbers
  1.     ' InputPin
  2.     Public Function InputPIN(ByRef pPinNum As Byte) As UInteger
  3.  
  4.         MessageBox.Show("Input Password and Push Enter !")
  5.  
  6.         Event_EndOfPinInput.Reset()
  7.         Event_EndOfPinInput.WaitOne()
  8.  
  9.         If txtPassword.InvokeRequired Then
  10.             Dim strPassword As String = Invoke(New GetPasswordTextCallback(AddressOf GetPasswordText), New Object() {}).ToString()
  11.             Dim byPassword As Byte() = StrToByteArray(strPassword)
  12.  
  13.             '...
  14.  
  15.  
  16.         End If
  17.         Return 1
  18.     End Function
BTW it's compact framework 2.0.

Thanks again
Sep 18 '12 #1
Share this Question
Share on Google+
2 Replies


P: 3
I convert it by conversion tools, see below code:

Expand|Select|Wrap|Line Numbers
  1.   Public Function InputPIN(ByRef pPinNum As Byte) As UInteger
  2.         MessageBox.Show("Input Password and Push Enter !")
  3.         Event_EndOfPinInput.Reset
  4.         Event_EndOfPinInput.WaitOne
  5.         If txtPassword.InvokeRequired Then
  6.             Dim strPassword As String = Invoke(New GetPasswordTextCallback(GetPasswordText), New Object(-1) {}).ToString
  7.             Dim byPassword() As Byte = StrToByteArray(strPassword)
  8.             pPinNum
  9.             Dim ps As Byte = _pPinNum
  10.             Dim i As Integer = 0
  11.             Do While (i < 4)
  12.                 (ps + i) = byPassword(i)
  13.                 i = (i + 1)
  14.             Loop
  15.         End If
  16.         Return 1
  17.     End Function
Sep 20 '12 #2

P: 2
Hello,

Thanks for the reply. Unfortunately no solution was found so I had to keep the code in a DLL.
Oct 5 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.