TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
fixit
NA
1
2.8k
C# to VB.net conversion: byte pointers etc
Sep 21 2012 7:17 PM
Hello,
I need to convert the following code from C# to Vb.net (it's part of an EMV API).
unsafe public uint InputPIN(ref byte pPinNum)
{
MessageBox.Show("Input Password and Push Enter !");
Event_EndOfPinInput.Reset();
Event_EndOfPinInput.WaitOne();
if (txtPassword.InvokeRequired)
{
string strPassword = Invoke(new GetPasswordTextCallback(GetPasswordText), new object[] { }).ToString();
byte[] byPassword = StrToByteArray(strPassword);
fixed (byte* _pPinNum = &pPinNum)
{
byte* ps = _pPinNum;
for (int i = 0; i < 4; i++)
*(ps + i) = byPassword[i];
}
}
return 1;
}
Result should be something like this:
' InputPin
Public Function InputPIN(ByRef pPinNum As Byte) As UInteger
MessageBox.Show("Input Password and Push Enter !")
Event_EndOfPinInput.Reset()
Event_EndOfPinInput.WaitOne()
If txtPassword.InvokeRequired Then
Dim strPassword As String = Invoke(New GetPasswordTextCallback(AddressOf GetPasswordText), New Object() {}).ToString()
Dim byPassword As Byte() = StrToByteArray(strPassword)
'...
End If
Return 1
End Function
I am stuck with the conversion of the 'fixed' structure. I understand VB.net has no equivalent for unsafe structures.
I think the functions needed to achieve this would be Marshal.Copy and/or GCHandle.
I am not sure why parameter pPinNum is returned as byte, I assume it's a pointer of some sort.
The function is defined like this in the API manual:
pfn_InputPIN
Display input PIN User Interface and give PIN that entered to EMV Kernel. You have to user
S/W PIN PED for receiving PIN. If not, this kernel will not work well.
Prototype BOOL (*pfn_InputPIN)(unsigned char *pPinNum);
Return BOOL
Whether input is available or not.
Parameter Description
pPinNum [out] Store PIN Number to this variable.
ex) 1234
pPinNum[0] = 1
pPinNum[1] = 2
pPinNum[2] = 3
pPinNum[3] = 4
Could do with some help ;-)
Thanks for looking.
Reply
Answers (
1
)
How will get registry information
bounce game using c#