extra spaces in string when returned from a dll
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14

Thread: extra spaces in string when returned from a dll

Hybrid View

  1. #1
    Join Date
    Sep 2005
    Posts
    13

    extra spaces in string when returned from a dll

    I have a dll that takes a string and character length. It is supposed to returned the string justified based on the character length (fixed field sizes). However, when the string returns from the dll its length is twice that specified by the character length variable passed to it. If anyone could provide some insight to this phenomenon I would appreciate it.

  2. #2
    Join Date
    Dec 2002
    Location
    London, UK
    Posts
    1,569

    Re: extra spaces in string when returned from a dll

    If I had to guess i would say there is some kind of issue between converting this string between ACSII and UNICODE (wide character) formats.
    Mike

  3. #3
    Join Date
    Sep 2005
    Posts
    13

    Re: extra spaces in string when returned from a dll

    Thanks Pinky98.

    Is there any work around for this tha I can implement?

  4. #4
    Join Date
    Apr 2003
    Posts
    1,755

    Smile Re: extra spaces in string when returned from a dll

    How are you calling the DLL? Is it using the "Private Declare" method. Try to change the parameter type. Instead of using "Byval var As String", make it a "Byref var as Any" and pass a pointer to a byte array to it.

    This is the original code (for example)
    Code:
    Private Declare Function GetWindowsDirectoryW Lib "kernel32" ( _
       ByVal lpBuffer As String, ByVal nSize As String) As Long
    
    Private Sub Form_Load()
       Dim strText As String
       strText = Space(255)
       Call GetWindowsDirectoryW(strText, 255)
       MsgBox strText
    End Sub
    It will give the result same as yours (as I can understand ur problem). Make the changes like this
    Code:
    Private Declare Function GetWindowsDirectoryW Lib "kernel32" ( _
       ByRef lpBuffer As Any, ByVal nSize As String) As Long
    
    Private Sub Form_Load()
       Dim strText As String, bArrStr() As Byte
       bArrStr = Space(255)
       Call GetWindowsDirectoryW(bArrStr(LBound(bArrStr)), 255)
       strText = bArrStr
       MsgBox strText
    End Sub
    Hope it will help you

  5. #5
    Join Date
    Sep 2005
    Posts
    13

    Re: extra spaces in string when returned from a dll

    no luck rxbagain

  6. #6
    Join Date
    Apr 2003
    Posts
    1,755

    Re: extra spaces in string when returned from a dll

    How is the function declared and how are you calling it? Can you post your declaration and the code that calls it here?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center