473,402 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

C# to VB.net conversion: byte pointers etc

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
2 2181
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
fixit
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

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

Similar topics

388
by: maniac | last post by:
Hey guys, I'm new here, just a simple question. I'm learning to Program in C, and I was recommended a book called, "Mastering C Pointers", just asking if any of you have read it, and if it's...
8
by: John Hanley | last post by:
I working in C. I haven't paid much attention to void pointers in the past, but I am wondering if I can use them for my various linked lists to save work. I have two different linked lists that...
289
by: napi | last post by:
I think you would agree with me that a C compiler that directly produces Java Byte Code to be run on any JVM is something that is missing to software programmers so far. With such a tool one could...
42
by: Abhishek Jha | last post by:
We cann't add two pointers, We cann't multiply two pointers, We cann't divide two pointers, But We can subtract two pointers. Why ?
47
by: sunglo | last post by:
Some time a go, in a discussion here in comp.lang.c, I learnt that it's better not to use a (sometype **) where a (void **) is expected (using a cast). Part of the discussion boiled down to the...
10
by: Kristian Nybo | last post by:
Hi, I'm writing a simple image file exporter as part of a school project, and I would like to write completely platform-independent code if at all possible. The problem I've run into is that...
5
by: Paminu | last post by:
Why make an array of pointers to structs, when it is possible to just make an array of structs? I have this struct: struct test { int a; int b;
15
by: Avinash | last post by:
Hi, I just wanted to confirm that sizeof for a pointer always returns the same value on a machine. I would appreciate if somebody would respond to this. Thanks.
5
by: jeremyje | last post by:
I'm writing some code that will convert a regular string to a byte for compression and then beable to convert that compressed string back into original form. Conceptually I have.... For...
160
by: raphfrk | last post by:
Is this valid? int a; void *b; b = (void *)a; // b points to a b += 5*sizeof(*a); // b points to a a = 100;
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.