Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a old vb6 project.Now I migrating it in vb.net on vs2008 and the solution plateform now I have to use 64bit.In the old code the variable hContext was declared as Integer.
VB
Dim hContext As Integer


And used as

VB
Dim rc As Integer
dwScope = SCARD_SCOPE_USER
rc = SCardEstablishContext(dwScope, 0, 0, hContext)


When I debug the code the hContext create problem.
This is due to it define as a Integer(32bit).
Now the problem is "What datatype should I use for hContext".I have also used different datatype like Long,ULong.
Posted

This is pointer, and all pointers gets the size of IntPtr which is 32-bit on 32-bit systems and and 64-bits on 64-bit systems, all other .NET types have the same size regardless of the instruction-set architecture of target assembly. Also, it's important that the last parameter is of out type.

So, the function prototype will be declared as
VB
Private Shared Function SCardEstablishContext(scope As System.UInt32, reserved1 As System.IntPtr, reserved2 As System.IntPtr, ByRef context As System.IntPtr) As Long


—SA
 
Share this answer
 
v2
Comments
Mehdi Gholam 7-Nov-11 22:04pm    
Missed that, 5'ed
Sergey Alexandrovich Kryukov 7-Nov-11 22:07pm    
Thank you, Mehdi.
--SA
From the Microsoft API we see the following :

C++
LONG WINAPI SCardEstablishContext(
  __in   DWORD dwScope,
  __in   LPCVOID pvReserved1,
  __in   LPCVOID pvReserved2,
  __out  LPSCARDCONTEXT phContext
);


As you can see the return type is a long which is 8 bytes on 32bit and 64bit systems.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 7-Nov-11 16:46pm    
Yes, but the question is about hContext. You should take into account that 3 parameters are pointers. Please see my solution.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900