-
What does this mean? Why does this happen?
I know when: It happens when I use CopyMemory() function and when I want to assign variable, returned by CopyMemory to my function (string variable).
Here's the code I use:
[code]
function MyFunction() As String
hLock = LockResource(hLoad)
hSize = SizeofResource(hInst, hFind)
ReDim b(0 To lsize) As String
CopyMemory b(0), hLock, hSize
FreeLibrary hInst
MyFunction = b
End function
-
Try this
Change your line:
ReDim b(0 To lsize) As String
to:
ReDim b(0 To lsize) As Byte
Then I know the CopyMemory will work. Can't vouch for the rest because I never play with DLL's at that level.
The trickle down effect of this is of course that you would have to change the return type of the function and then you probably will have more headaches.
So to convert a byte array to a string, I do the following: (There are no doubt better ways, so if someone else knows of one post a reply too!)
Code:
...
Public Declare Sub CopyMemory Lib "kernel32" Alias _ "RtlMoveMemory" (lpvDest As Any, lpvSource As Any, _
ByVal cbCopy As Long)
...
Dim sTmp as String
Dim lVal,lLen as Long
sTmp = String$(lLen + 1, Chr$(0))
CopyMemory ByVal sTmp, ByVal lVal, lLen
Dim nullPos As Integer
nullPos = InStr(1, sTmp, Chr$(0))
If nullPos > 0 Then sTmp = Left(sTmp, nullPos - 1)
...
I hope this helps.
Regards
Paul Lewis
-
The thing I was loading from dll was string, but declared variable was byte so that caused error. So I changed it to string and it worked.
I'll try your example and tell you if it worked.
-
I tried it and it works.
THANKS, PAUL!!!