LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to set the parameter when call DLL

I am trying to use the System32\WinSCard.dll. When calling the function below, may I know how to set the 4th input parameter. Thanks.

retval = SCardEstablishContext(0, 0, 0, hContext)

Download All
0 Kudos
Message 1 of 7
(3,145 Views)

I haven't got a Scard reader so I can't debug the advise which I'm giving you but, I looked at your code (according to this documentation WinScard.dll) and I found out that you are passing the two reserved parameters as a value insted of pointers of value. The LPC data are Long Pointer C so you have to pass them as pointers. The same is true for the last parameter. So pass them as a pointers. The other thing I think you have set wrong is the calling system of the dll, you are calling the dll as a C dll instead of WINAPI dll. I think these are your bugs....

Ricky
Italian Developer engineer
www.www.selt-sistemi.com
Message 2 of 7
(3,135 Views)

@g_Ricky wrote:

I haven't got a Scard reader so I can't debug the advise which I'm giving you but, I looked at your code (according to this documentation WinScard.dll) and I found out that you are passing the two reserved parameters as a value insted of pointers of value. The LPC data are Long Pointer C so you have to pass them as pointers. The same is true for the last parameter. So pass them as a pointers. The other thing I think you have set wrong is the calling system of the dll, you are calling the dll as a C dll instead of WINAPI dll. I think these are your bugs....


This is about half right.  The documentation to which you linked says that the two reserved values must be NULL, so it is correct to pass them as integers by value (otherwise you're passing pointers to memory locations that contain zero, which is not the same as passing a null pointer).  However, the hContext parameter IS a pointer and should be passed as one.  The calling convention comment is exactly right - it's declared as WINAPI and should be called that way.

Message 3 of 7
(3,116 Views)

So the steps are:

Double click Call Library Function Node

1) On Function Tab, Change Calling Convention from c to stdcall. I think you should also consider selecting Run in any thread but I dont really know your application.

2)  In parameter Tab, select hContext change Pass to Pointer to value

The best way I would say to go around with calling dlls and header files is by using import shared library wizard provided you have dll and header files.

You could find examples and tutorials on ni website for using import shared library wizard.

 

Hope it helps!

Message 4 of 7
(3,109 Views)

Thanks, it works now, but I tried to use 3 functions as below.

 

But when calling the 2nd function as attached, the LV will quit. Any suggestion, thanks.

 

        retval = SCardEstablishContext(0, 0, 0, hContext)
        retval = SCardListReaders(hContext, mzGroup, ReaderList, pcchReaders) 'This number of readers connected
        retval = SCardListReaders(hContext, mzGroup, ReaderList, pcchReaders) 'Gives the list of the readers

Download All
0 Kudos
Message 5 of 7
(3,100 Views)

As before your're making mistakes in the calling of the parameters to pass to the functions. You are passing the pcchReaders parameter as value but the functions expects a DWORD pointer. So this means you have to pass a pointer to a U16 type. You have to follow the documentation of the library if you do not want to make mistakes.

Ricky
Italian Developer engineer
www.www.selt-sistemi.com
Message 6 of 7
(3,092 Views)

Unfortunately you're not handling this correctly at all.  Do you have some experience using pointers in C?  If not, it's hard to get this right.

 

This is one of the cases where you do NOT want the LabVIEW call to match the function prototype, and you need the two different calls to the same function to be configured differently.  It is also critical to understand that a NULL pointer is not the same as passing a pointer to an empty string (which is what you're doing).  To pass a null pointer, configure that parameter as a pointer-sized integer passed by value, and pass that as 0.  Also, when you call SCardListReaders the second time, you must pre-allocate the ReaderList string so that it has a length equal to the value returned in pcchReaders in the first call.  I think it should look like this, but when I run it on my machine it does crash LabVIEW.  I don't know if that's due to different versions of the appropriate library, a lack of SCardReaders, or something else.

 

SCardListReaders.png 

 

One more thing: you should pass the hContext value from SCardEstablishContext to SCardListReaders, as shown in the above image.

Message 7 of 7
(3,077 Views)