469,592 Members | 1,815 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,592 developers. It's quick & easy.

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 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!
Apr 7 '06 #1
3 11375
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

"Ling Chen Wu" <Ling Chen Wu@discussions.microsoft.com> wrote in message
news:7E**********************************@microsof t.com...
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!

Apr 7 '06 #2
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!

Apr 7 '06 #3
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.
--
Best,
Rob
"Ling Chen Wu" wrote:
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!

Apr 21 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Andreas Müller | last post: by
2 posts views Thread by Frank | last post: by
7 posts views Thread by Frank | last post: by
5 posts views Thread by Brian C | last post: by
33 posts views Thread by Jordan Tiona | last post: by
14 posts views Thread by gustavo | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.