I have a old VB6 project.Now I migrating it in VB.Net on vs2008 and the solution platform now I have to use 64bit.In the old code the variable hContext was declared as Integer.
Dim hContext As Integer
And used as:
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, IntPtr….
NOTE
When I debug the code the hcontext take 4byte address.but in 64bit I take hContext as IntPtr which is platform dependent,But it show only 1byte address. And I am not able to establish the connection.
I suspect the question is “what is the correct signature for SCardEstablishContext in a 64-bit project?”
The C WinAPI signature is as follows:
Pointer types (“LP…”) should be
IntPtrand LONG/DWORD types should map toInteger— this will be correct for a WinAPI call in either a 32-bit or a 64-bit build. (In some cases it is nice to specify a managed structure type instead ofIntPtrand let the .NET interoperability/pinvoke automatically marshal everything.)pinvoke.net is sometimes helpful — see pinvoke.net: SCardEstablishConnection
and *note how the VB.NET signature at top is wrong— but care needs to be taken because definitions are sometimes incorrect and/or incomplete 😉The correct pinvoke signature, for an opaque context value, is:
Happy coding.