Accessing char ** C-programming Construct via DLL in VB5 
Author Message
 Accessing char ** C-programming Construct via DLL in VB5

Gang:

Please bare with me, I am new to VB5...

I am trying to access the Ghostscript 5.03 for Windows
DLL "gsdll32.dll" via the Private Declare Sub construct
in VB5. There are several functions present in this DLL, but
I started with gsdll_revision which returns the product name,
copyright information, the revision number, and the revision
date.  

In the documentation for gsdll_revision, we are told that the
function's arguments are:

 char **product;
 char **copyright;
 long *revision;
 long *revisiondate;

I created my VB declare as follows:

 Private Declare Sub gsdll_revision Lib "gsdll32" (ByVal product As
String, ByVal copyright As String, rev As Long, revdate As Long)

I then ran the program to test the results:

 Private Sub Command1_Click()

  Dim product As String
  Dim copyright As String
  Dim revision As Long
  Dim revisiondate As Long
  Dim rc As Integer

  gsdll_revision product, copyright, revision, revisiondate

  rc = MsgBox("Product=" + product, vbOKOnly, "Product Information")
  rc = MsgBox("Copyright=" + copyright, vbOKOnly, "Copyright
Information")
  rc = MsgBox("Revision=" + Str(revision), vbOKOnly, "Revision
Information")
  rc = MsgBox("Product=" + Str(revisiondate), vbOKOnly, "Revision Date
Information")

 End Sub

The messagebox for product and copyright both returned blank strings,
while the revision returned the number 503 and revisiondate returned
19970808,
both of which are correct.

I have checked the documentation provided with VB5 on accessing DLLs,
but I am not able to find anything about character pointers to
pointers.  I have
tried to remove the "ByVal"s in the declaration and running it that way,
but I
get a crash.  

Curious, though, when I force the product and copyright string Dim's to
a fixed length of 10...

 Dim product As String * 10
 Dim copyright As String * 10

 ...both the product and copyright return jibberish characters. (I am
assuming that what I am getting is the address to a memory location, but
I do not know that
for sure.)

Any help would be greatly appreciated!

Thanks,
Scott



Fri, 24 Nov 2000 03:00:00 GMT  
 Accessing char ** C-programming Construct via DLL in VB5

Scott -
    Char ** is a fair representation of "ByRef xx As String", but the catch
is that you have to provide a pre-allocated string.  Fixed-length strings are
not very efficient for this.

    Also, VB/32 expects Unicode strings, so you'll probably have to use
StrConv to get them into the proper form.

  Dim sProduct As String
  sProduct = String$(100, 0)

  ... your call ...

  sProduct = StrConv(sProduct, vbUnicode)

--

     Jim Mack
     MicroDexterity, Inc
     PO Box 5372
     Plymouth, MI  48170-5372

     http://www.microdexterity.com



     Fax:  +1 734-453-8942

Quote:

> Gang:

> Please bare with me, I am new to VB5...

> I am trying to access the Ghostscript 5.03 for Windows
> DLL "gsdll32.dll" via the Private Declare Sub construct
> in VB5. There are several functions present in this DLL, but
> I started with gsdll_revision which returns the product name,
> copyright information, the revision number, and the revision
> date.  

> In the documentation for gsdll_revision, we are told that the
> function's arguments are:

>  char **product;
>  char **copyright;
>  long *revision;
>  long *revisiondate;

> I created my VB declare as follows:

>  Private Declare Sub gsdll_revision Lib "gsdll32" (ByVal product As
> String, ByVal copyright As String, rev As Long, revdate As Long)

> I then ran the program to test the results:

>  Private Sub Command1_Click()

>   Dim product As String
>   Dim copyright As String
>   Dim revision As Long
>   Dim revisiondate As Long
>   Dim rc As Integer

>   gsdll_revision product, copyright, revision, revisiondate

>   rc = MsgBox("Product=" + product, vbOKOnly, "Product Information")
>   rc = MsgBox("Copyright=" + copyright, vbOKOnly, "Copyright
> Information")
>   rc = MsgBox("Revision=" + Str(revision), vbOKOnly, "Revision
> Information")
>   rc = MsgBox("Product=" + Str(revisiondate), vbOKOnly, "Revision Date
> Information")

>  End Sub

> The messagebox for product and copyright both returned blank strings,
> while the revision returned the number 503 and revisiondate returned
> 19970808,
> both of which are correct.

> I have checked the documentation provided with VB5 on accessing DLLs,
> but I am not able to find anything about character pointers to
> pointers.  I have
> tried to remove the "ByVal"s in the declaration and running it that way,
> but I
> get a crash.  

> Curious, though, when I force the product and copyright string Dim's to
> a fixed length of 10...

>  Dim product As String * 10
>  Dim copyright As String * 10

>  ...both the product and copyright return jibberish characters. (I am
> assuming that what I am getting is the address to a memory location, but
> I do not know that
> for sure.)

> Any help would be greatly appreciated!

> Thanks,
> Scott



Fri, 24 Nov 2000 03:00:00 GMT  
 Accessing char ** C-programming Construct via DLL in VB5

Whenever you pass a string to a DLL ByVal, the string is automatically
converted to ANSI during the call, and back again upon the return of the dll
call.  As Jim Mack said though, strings do have to be preallocated, but
never use the StrConv function when passing a string to a DLL byval.  If
used, a ANSI-->Unicode conversion would occur twice for the same string
and/or vice versa.  See a simplified example for the correct use of the
GetComputerName API call (tested & works perfectly) below.
----------------------
Shane Krueger

'-------Start VB GetComputerName demonstration code------
Private Declare Function APIGetComputerName Lib "kernel32" Alias _
  "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Public Function GetComputerName() As String
  Dim Dr$

  Dr$ = Space$(1000)
  If APIGetComputerName(Dr$, Len(Dr$)) = 0 Then Err.Raise 75
  GetComputerName = Left$(Dr$, InStr(Dr$, Chr$(0)) - 1)
End Function
'-------End VB GetComputerName demonstration code------


Quote:
>Scott -
>    Char ** is a fair representation of "ByRef xx As String", but the catch
>is that you have to provide a pre-allocated string.  Fixed-length strings
are
>not very efficient for this.

>    Also, VB/32 expects Unicode strings, so you'll probably have to use
>StrConv to get them into the proper form.

>  Dim sProduct As String
>  sProduct = String$(100, 0)

>  ... your call ...

>  sProduct = StrConv(sProduct, vbUnicode)

>--

>     Jim Mack
>     MicroDexterity, Inc
>     PO Box 5372
>     Plymouth, MI  48170-5372

>     http://www.microdexterity.com



>     Fax:  +1 734-453-8942


>> Gang:

>> Please bare with me, I am new to VB5...

>> I am trying to access the Ghostscript 5.03 for Windows
>> DLL "gsdll32.dll" via the Private Declare Sub construct
>> in VB5. There are several functions present in this DLL, but
>> I started with gsdll_revision which returns the product name,
>> copyright information, the revision number, and the revision
>> date.

>> In the documentation for gsdll_revision, we are told that the
>> function's arguments are:

>>  char **product;
>>  char **copyright;
>>  long *revision;
>>  long *revisiondate;

>> I created my VB declare as follows:

>>  Private Declare Sub gsdll_revision Lib "gsdll32" (ByVal product As
>> String, ByVal copyright As String, rev As Long, revdate As Long)

>> I then ran the program to test the results:

>>  Private Sub Command1_Click()

>>   Dim product As String
>>   Dim copyright As String
>>   Dim revision As Long
>>   Dim revisiondate As Long
>>   Dim rc As Integer

>>   gsdll_revision product, copyright, revision, revisiondate

>>   rc = MsgBox("Product=" + product, vbOKOnly, "Product Information")
>>   rc = MsgBox("Copyright=" + copyright, vbOKOnly, "Copyright
>> Information")
>>   rc = MsgBox("Revision=" + Str(revision), vbOKOnly, "Revision
>> Information")
>>   rc = MsgBox("Product=" + Str(revisiondate), vbOKOnly, "Revision Date
>> Information")

>>  End Sub

>> The messagebox for product and copyright both returned blank strings,
>> while the revision returned the number 503 and revisiondate returned
>> 19970808,
>> both of which are correct.

>> I have checked the documentation provided with VB5 on accessing DLLs,
>> but I am not able to find anything about character pointers to
>> pointers.  I have
>> tried to remove the "ByVal"s in the declaration and running it that way,
>> but I
>> get a crash.

>> Curious, though, when I force the product and copyright string Dim's to
>> a fixed length of 10...

>>  Dim product As String * 10
>>  Dim copyright As String * 10

>>  ...both the product and copyright return jibberish characters. (I am
>> assuming that what I am getting is the address to a memory location, but
>> I do not know that
>> for sure.)

>> Any help would be greatly appreciated!

>> Thanks,
>> Scott



Sat, 25 Nov 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Accessing char ** C-programming Construct via DLL in VB5

2. Accessing char ** C-programming Construct via DLL in VB5

3. Distribution of VB-constructed programs

4. VB5 program calls Oracle stored procedure via ODBC

5. Distribution of VB-constructed programs

6. cant get Word to pass values via DDE or DDEAUTO to my VB5 program

7. Constructing a zip code program

8. Localization via DLLs in VB5

9. How to access Access table with VB5 program?

10. Access via WWW / ASP programming question...HELP!

11. Export Access Queries to a Word Doc via a VB6 Program

12. accessing another program via lan cards ?

 

 
Powered by phpBB® Forum Software