Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert C++ header for use in VB6

Status
Not open for further replies.

gmmastros

Programmer
Feb 15, 2005
14,909
US
I'm trying to print to a Zebra printer (p430i) from within VB6. I also need to encode mifare cards with this printer. All of the documentation and sample code for the mifare functionality is written in C++.

I am trying to convert this code to VB6.

Code:
typedef struct S_CARD_AND_TIMEOUT
{
	unsigned char ucCard;
	unsigned char ucIsTimeoutSpecified;
	unsigned char ucTimeout_50msBased;
}sCARD_AND_TIMEOUT;

typedef struct S_GET_CARD_A
{
   /* IN: Size of the following buffer */
   /* OUT: Serial Number length */
   int iSerialNumberSize;
   /* Can be from 1 to 3 Cascade Level */
   unsigned char *pucSerialNumber;
   unsigned short usATQA;
   unsigned char ucSAK;
}sGET_CARD_A;

typedef int (CALLBACK *ZBRMF_ISO14443_3_A_GetCard)(HANDLE hPrinter, int printerType, sCARD_AND_TIMEOUT* cardAndTimeout, sGET_CARD_A* getCardAInfo, int* err);

Code:
// Timeout and Card Management Struct Definitions
sCARD_AND_TIMEOUT cardAndTimeout;                    // Card And Timeout Structure
memset(&cardAndTimeout, 0, sizeof(cardAndTimeout));

cardAndTimeout.ucIsTimeoutSpecified = 0x01;         // Timeout specified
cardAndTimeout.ucTimeout_50msBased = 0x3C;          // Timeout value (~3 seconds)
cardAndTimeout.ucCard = 0x00;                       // First Card

// Card Target is the first ISO14443A Card Found in Field
sGET_CARD_A getCardA;                              // Card A Info Structure
memset(&getCardA, 0, sizeof(getCardA));

unsigned char serialNumberA[10];                   // Three cascade level length
getCardA.pucSerialNumber = serialNumberA;
getCardA.iSerialNumberSize = sizeof(serialNumberA);

// Get ISO14443 A Card
/* Performs the following sequence of commands
           - RF Reset
           - Request A
           - Anticollision
           - Select
*/
err = zsdkISO14443_3_A_GetCard(hPrinter, printerType, &cardAndTimeout, &getCardA, &error);
if ((!err || error) != ZBR_ERROR_NO_ERROR)
  {
  printf("\n\nISO14443_3_A_GetCard Failed");
  throw error;
  }

This is what I have.

Code:
Public Type S_CARD_AND_TIMEOUT
    ucCard As Byte
    ucIsTimeoutSpecified As Byte
    ucTimeout_50msBased As Byte
End Type

Public Type S_GET_CARD_A
   '/* IN: Size of the following buffer */
   '/* OUT: Serial Number length */
   iSerialNumberSize As Long
   '/* Can be from 1 to 3 Cascade Level */
   pucSerialNumber As Byte
   usATQA As Long
   ucSAK As Byte
End Type

Public Declare Function ZBRGPMF_ISO14443_3_A_GetCard _
    Lib "ZBRGPMF" ( _
    ByVal hPrinter As Long, _
    ByVal PrinterType As Long, _
    ByRef cardAndTimeout As S_CARD_AND_TIMEOUT, _
    ByRef getCardAInfo As S_GET_CARD_A, _
    ByRef err As Long) _
    As Long

This is the code I use to call it:
Code:
    Dim ReturnValue As Long
    Dim Error As Long
    Dim ErrorMessage As String
    Dim CardType As Byte
    Dim i As Long
    
'
'    // Timeout and Card Management Struct Definitions
    '// Card And Timeout Structure
    '   ucIsTimeoutSpecified --  Timeout specified
    '   ucTimeout_50msBased  --  Timeout value (~3 seconds)
    '               // First Card

    Dim cardAndTimeout As S_CARD_AND_TIMEOUT
'    memset(&cardAndTimeout, 0, sizeof(cardAndTimeout));

    cardAndTimeout.ucIsTimeoutSpecified = &H1
    cardAndTimeout.ucTimeout_50msBased = &H3C
    cardAndTimeout.ucCard = &H0

'    // Card Target is the first ISO14443A Card Found in Field
';                               // Card A Info Structure
';                    // Three cascade level length
    Dim getCardA As S_GET_CARD_A
'    memset(&getCardA, 0, sizeof(getCardA));
'
    Dim serialNumberA(9) As Byte
    'getCardA.pucSerialNumber = serialNumberA
    getCardA.iSerialNumberSize = UBound(serialNumberA) + 1

'    // Get ISO14443 A Card
'        /* Performs the following sequence of commands
'             - RF Reset
'             - Request A
'             - Anticollision
'             - Select
'        */
    ReturnValue = ZBRGPMF_ISO14443_3_A_GetCard(hPrinter, printerType, cardAndTimeout, getCardA, Error)
    [!]' ReturnValue = 0[/!]
    If Error <> ZBR_ERROR_NO_ERROR Then
        [!]' The Error variable is 63[/!]
        ErrorMessage = TranslateError(Error)
        GoTo OSIErrorHandler
    End If


I have this code in a regular bas module. There are other dll functions that I call (which work). When I try to call this function, I don't get any run time errors but I do get an error.

The last parameter to the function is err. After calling the function, the err value is 63 which translates to invalid parameter.

I've been struggling and googling, but can't seem to get it right.


-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 

It's been a while since I delved into VB6, but my initial thought is that the printer handle (hPrinter) has not been set to a valid printer. Here is a link that may help.


Mark

"You guys pair up in groups of three, then line up in a circle."
- Bill Peterson, a Florida State football coach
 
Mark, thanks for the reply.

I know I have a good handle to the printer because other calls to API's in the same dll are working properly. Basically, I get the printer handle, I load the mifare card in to the card writer/reader position, and then try to get the card information (which this post is about). It fails, of course (or I wouldn't be posting). After it fails, I unload the card which spits it out to the "out bin" on the side of the machine. Finally, I close the printer handle.

In short, some of the api calls are working as they should, but this one is not.



-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
I eventually got this to work. Of course I changed it to:

pucSerialNumber As Long



-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top