CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: Arrays

  1. #1
    Join Date
    Jan 2000
    Posts
    46

    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



  2. #2
    Join Date
    Feb 2000
    Location
    Indiana
    Posts
    308

    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[][]);




  3. #3
    Join Date
    Jan 2000
    Posts
    46

    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


  4. #4
    Join Date
    Feb 2000
    Location
    Indiana
    Posts
    308

    Re: Arrays

    Did you try sending it a "padded" string?


  5. #5
    Join Date
    Jan 2000
    Posts
    46

    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


  6. #6
    Join Date
    Feb 2000
    Location
    Indiana
    Posts
    308

    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.


  7. #7
    Join Date
    Jan 2000
    Posts
    46

    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


  8. #8
    Join Date
    Feb 2000
    Location
    Indiana
    Posts
    308

    Re: Arrays


    Dim sRetVal as string
    sRetVal = Space$(33)
    'call the function





  9. #9
    Join Date
    Jan 2000
    Posts
    46

    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
  •  





Click Here to Expand Forum to Full Width

Featured