How to declare char string pointer in VB?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ling Chen Wu

    #1

    How to declare char string pointer in VB?

    Hi,

    I need to call a dll function but have no idea how to declare the function
    in VB.NET

    In the .h file, it is declare as follows:

    int CALLBACK gscBsiGcReadTag List(
    IN UTILCardHandle hCard, /* Card communication handle */
    IN unsigned char* usAID, /* Container AID */
    IN unsigned int unAIDLen, /* Container AID length */
    OUT GCTag* pTagArray,/* Array of tags */
    INOUT unsigned int* pnTagNb /* Number of tags in array */
    );



    In the C sample code, it is called as follows

    void CreateDataInCon tainer()
    {
    long lResp = BSI_OK;
    unsigned char usAID[BUFSIZ];
    unsigned int unAIDLen=0;
    char szLecture[BUFSIZ];
    GCTag ucTag=0;
    unsigned int unTag=1;
    unsigned char usValue[500];
    unsigned int unValueLen=0;

    printf ("\ngscBsiGcDat aCreate");

    unAIDLen = sizeof (usAID);
    GetContainerAID ( usAID, &unAIDLen);

    GetString ("\nEnter Tag", szLecture, sizeof (szLecture));
    sscanf (szLecture, "%d", &unTag);

    ucTag = (char)unTag;

    GetString ("\nEnter Data Value ", szLecture, sizeof (szLecture));
    strcpy ((char *)usValue, szLecture);
    unValueLen = strlen (szLecture);

    printf("\nSize of value=%d",unVal ueLen);

    lResp = gscBsiGcDataCre ate(
    hCard,
    usAID,
    unAIDLen,
    ucTag,
    usValue,
    unValueLen
    );
    if (lResp != BSI_OK)
    {
    DisplayError(" ... ", lResp);
    }
    else
    {
    printf ("\n ... OK\n");
    }
    }


    So, can anyone help me with the declaration and calling in VB.NET or VB6?

    Thanks!
  • Claes Bergefall

    #2
    Re: How to declare char string pointer in VB?

    So which method are you trying to call?
    You gave the .h file definition of gscBsiGcReadTag List but your code calls
    the method gscBsiGcDataCre ate

    If you need to pass a string as an out parameter, use a StringBuilder object
    (initialize it to the required size in the constructor)

    Declare Auto Sub SomeMethod Lib "somelib.dl l" (ByVal sb As StringBuilder,
    ByVal len As Integer)
    ....
    Dim sb As New StringBuilder(2 00)
    SomeMethod(sb, sb.Capacity)

    /claes

    "Ling Chen Wu" <Ling Chen Wu@discussions. microsoft.com> wrote in message
    news:7E245EE5-0C08-48C3-8C2B-B4E533954A49@mi crosoft.com...[color=blue]
    > Hi,
    >
    > I need to call a dll function but have no idea how to declare the function
    > in VB.NET
    >
    > In the .h file, it is declare as follows:
    >
    > int CALLBACK gscBsiGcReadTag List(
    > IN UTILCardHandle hCard, /* Card communication handle */
    > IN unsigned char* usAID, /* Container AID */
    > IN unsigned int unAIDLen, /* Container AID length */
    > OUT GCTag* pTagArray,/* Array of tags */
    > INOUT unsigned int* pnTagNb /* Number of tags in array */
    > );
    >
    >
    >
    > In the C sample code, it is called as follows
    >
    > void CreateDataInCon tainer()
    > {
    > long lResp = BSI_OK;
    > unsigned char usAID[BUFSIZ];
    > unsigned int unAIDLen=0;
    > char szLecture[BUFSIZ];
    > GCTag ucTag=0;
    > unsigned int unTag=1;
    > unsigned char usValue[500];
    > unsigned int unValueLen=0;
    >
    > printf ("\ngscBsiGcDat aCreate");
    >
    > unAIDLen = sizeof (usAID);
    > GetContainerAID ( usAID, &unAIDLen);
    >
    > GetString ("\nEnter Tag", szLecture, sizeof (szLecture));
    > sscanf (szLecture, "%d", &unTag);
    >
    > ucTag = (char)unTag;
    >
    > GetString ("\nEnter Data Value ", szLecture, sizeof (szLecture));
    > strcpy ((char *)usValue, szLecture);
    > unValueLen = strlen (szLecture);
    >
    > printf("\nSize of value=%d",unVal ueLen);
    >
    > lResp = gscBsiGcDataCre ate(
    > hCard,
    > usAID,
    > unAIDLen,
    > ucTag,
    > usValue,
    > unValueLen
    > );
    > if (lResp != BSI_OK)
    > {
    > DisplayError(" ... ", lResp);
    > }
    > else
    > {
    > printf ("\n ... OK\n");
    > }
    > }
    >
    >
    > So, can anyone help me with the declaration and calling in VB.NET or VB6?
    >
    > Thanks![/color]


    Comment

    • Ling Chen Wu

      #3
      Re: How to declare char string pointer in VB?

      My apologies, the calling sample code is as follows:

      void ListOfTagsInCon tainer()
      {
      long lResp = BSI_OK;
      unsigned char usAID[BUFSIZ];
      unsigned int unAIDLen=0;
      GCTag ucTag=0;
      unsigned int unTag=1;
      unsigned int unTagNb;
      GCTag* pTagArray=NULL;
      int i;

      printf ("\ngscBsiGcRea dTagList");

      unAIDLen = sizeof (usAID);
      GetContainerAID (usAID, &unAIDLen);

      lResp = gscBsiGcReadTag List(
      hCard,
      usAID,
      unAIDLen,
      NULL,
      &unTagNb
      );

      My main problem is with the 2nd parameter usAID, which is a string passed
      into the function. The string value is Chr(&HA0) + Chr(&H0) + Chr(&H0) +
      Chr(&H0) + Chr(&H79) + Chr(&HA0) + Chr(&H86).

      Thanks!



      Comment

      • Rob Allen digitaldangerx yahoodotcom >

        #4
        Re: How to declare char string pointer in VB?

        have a look at the MarshalAs<>

        I was able to call a C DLL that passed back a char* and get it to come back
        as a String object.

        Here is my C function prototype and the declare statement in VB.NET 2005:

        'char* ARC_ECHELLE_API ARC_Echelle_Get _Module_Name (long , long);
        Public Declare Auto Function ARC_Echelle_Get _Module_Name Lib
        "ARC_Echelle.dl l" _
        (ByVal Echelle_Type As Integer, ByVal Echelle_Module As Integer) As
        <MarshalAs(Unma nagedType.LPStr )> String

        Sarch the MSDN help for "System.Runtime .InteropService s Namespace" and look
        at Marshal and MarshalAs Attribute. I think it will help.


        --
        Best,
        Rob


        "Ling Chen Wu" wrote:
        [color=blue]
        > My apologies, the calling sample code is as follows:
        >
        > void ListOfTagsInCon tainer()
        > {
        > long lResp = BSI_OK;
        > unsigned char usAID[BUFSIZ];
        > unsigned int unAIDLen=0;
        > GCTag ucTag=0;
        > unsigned int unTag=1;
        > unsigned int unTagNb;
        > GCTag* pTagArray=NULL;
        > int i;
        >
        > printf ("\ngscBsiGcRea dTagList");
        >
        > unAIDLen = sizeof (usAID);
        > GetContainerAID (usAID, &unAIDLen);
        >
        > lResp = gscBsiGcReadTag List(
        > hCard,
        > usAID,
        > unAIDLen,
        > NULL,
        > &unTagNb
        > );
        >
        > My main problem is with the 2nd parameter usAID, which is a string passed
        > into the function. The string value is Chr(&HA0) + Chr(&H0) + Chr(&H0) +
        > Chr(&H0) + Chr(&H79) + Chr(&HA0) + Chr(&H86).
        >
        > Thanks!
        >
        >
        >[/color]

        Comment

        Working...