-
September 15th, 2005, 03:11 PM
#1
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.
-
September 16th, 2005, 06:55 AM
#2
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
-
September 16th, 2005, 11:16 AM
#3
Re: extra spaces in string when returned from a dll
Thanks Pinky98.
Is there any work around for this tha I can implement?
-
September 16th, 2005, 11:43 AM
#4
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
-
September 16th, 2005, 12:31 PM
#5
Re: extra spaces in string when returned from a dll
-
September 16th, 2005, 01:04 PM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|