CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2007
    Posts
    19

    Question about String Pointers ??

    hi
    i work with a c++ dll in vb6...
    with a method in dll i can read/write data such as string use pointers.
    for exam. i write to memory(dll) 'hello' string ,but when i get pointer to read data ,the string has strange character ?!
    does C++ dll convert my string to ANSI ?

    also in vb6 if StrPtr(A)=0 ,it means A is nullstring. now is there a way to copy an string value(not null) to null variable using pointer ? specially when we have only pointer of null variable.
    thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: about String Pointers ??

    VB6 doesn't have string pointers, like C+ You can pass by value or by reference. You can have a string array. VB6 is Unicode based as well
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Aug 2007
    Posts
    19

    Re: about String Pointers ??

    VB6 doesn't have string pointers
    but in vb6 we have VarPtr , StrPtr and ObjPtr .

    VB6 is Unicode based as well
    i know ,but maybe C++ not. and i have problem with convert string from C to vb6.

  4. #4
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: about String Pointers ??

    To pass string data from and to a dll you declare the parameter ByVal xxx as String.
    This may sound illogical but it will pass a real LPSZSTR stringpointer (pointer to a zero terminated string) to the dll function.

    Example
    Code:
    Public Declare Function StringFunc Lib "myDll.dll" ( _
           ByVal Buffer As String, _
           ByVal Size As Long _
      ) As Long
    If you intend the dll to return data by filling this string you better pass the max length in the Size parameter, so your dll knows how many characters it may put into the Buffer area.

    If you pass a parameter ByRef as String you will pass a pointer to a BStr structure which in turn contains the length and a stingpointer to the actual characters. So it is most likely that you see 'strange characters' because it is just some memory conents around the BStr.

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