|
-
February 23rd, 2000, 11:54 AM
#1
Arrays
Hi,
I am writing code that uses a DLL. The function is that uses the DLL, does not take any values in. It ouptputs a really long string. I have the same code in Visual C++, where the value that is returned is of type char[33].
How can I do the same in Visual Basic? I tried to define an array as follows:
option explicit
private HostId() as string
then the function definition in a module
Declare Function GenerateId Lib "PLId.DLL" (ByRef HostId() As String) As Long
this is how I'm using the function:
dim rc as long
rc = GenerateId(HostId())
This gives me an exception. If I define the array with the size like private HostId(33) as string, then the function gives me invalid function arguments error.
What I am doing wrong??? Please help!!!
Thank you in advance.
Avni
-
February 23rd, 2000, 12:04 PM
#2
Re: Arrays
A VB String handles the array of characters for you. What you are telling the compiler in your declare (kind of) is long int GenerateId(char &HostId[][]);
-
February 23rd, 2000, 12:16 PM
#3
Re: Arrays
Hi,
That's what I thought too, but I keep getting errors when I declared the ID as just string.
I tried again to declare the ID as string, in both the function declaration and the function call. Now, the ID returns empty string....
Thank you
avni
-
February 23rd, 2000, 12:31 PM
#4
Re: Arrays
Did you try sending it a "padded" string?
-
February 23rd, 2000, 12:39 PM
#5
Re: Arrays
Hi Kyle,
No. I don't really know how to do that... 
Can you please provide an example???
Thank you for your help...
Avni
-
February 23rd, 2000, 01:06 PM
#6
Re: Arrays
Just doing a little brushing up on my API. VB stores string variables with the C datatype BSTR. This is more than just an array of characters. The first four bytes are information on the size of the string. Most C/C++ functions that take a string argument expect a LPSTR. The book I'm reading says that VB will always pass strings by reference no matter what the declaration. If you specify ByRef, it will pass a reference to a BSTR. If you specify ByVal, it will pass a reference to a LPSTR. You might want to check this out.
-
February 23rd, 2000, 01:16 PM
#7
Re: Arrays
Hi Kyle,
If I pass the string in the DLL as byref, i get exception error... If I pass as byval, then my program gives error, invalid function arguments...
Thanks for all your help.
Avni
-
February 23rd, 2000, 01:52 PM
#8
Re: Arrays
Dim sRetVal as string
sRetVal = Space$(33)
'call the function
-
February 23rd, 2000, 02:43 PM
#9
Re: Arrays
Hi Kyle,
Thank you very very much.... The code is working with the addition of that code snippet you wrote...
Thank you... I really appreciate all your help.
avni
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|