How to declare char string pointer in VB?

G

Guest

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 gscBsiGcReadTagList(
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 CreateDataInContainer()
{
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 ("\ngscBsiGcDataCreate");

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",unValueLen);

lResp = gscBsiGcDataCreate(
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!
 
C

Claes Bergefall

So which method are you trying to call?
You gave the .h file definition of gscBsiGcReadTagList but your code calls
the method gscBsiGcDataCreate

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.dll" (ByVal sb As StringBuilder,
ByVal len As Integer)
....
Dim sb As New StringBuilder(200)
SomeMethod(sb, sb.Capacity)

/claes
 
G

Guest

My apologies, the calling sample code is as follows:

void ListOfTagsInContainer()
{
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 ("\ngscBsiGcReadTagList");

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

lResp = gscBsiGcReadTagList(
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!
 
G

Guest

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.dll" _
(ByVal Echelle_Type As Integer, ByVal Echelle_Module As Integer) As
<MarshalAs(UnmanagedType.LPStr)> String

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