|
-
Jul 13th, 2000, 04:11 PM
#1
Thread Starter
Addicted Member
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
Zvonko Bostjancic
Ilirska Bistrica, Slovenia
[email protected]
Using VS6 Professional with SP3
Programming mostly in VB and I've started to learn VC++ & MFC
-
Jul 13th, 2000, 07:24 PM
#2
Hyperactive Member
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
-
Jul 14th, 2000, 06:05 AM
#3
Thread Starter
Addicted Member
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.
Zvonko Bostjancic
Ilirska Bistrica, Slovenia
[email protected]
Using VS6 Professional with SP3
Programming mostly in VB and I've started to learn VC++ & MFC
-
Jul 14th, 2000, 07:40 AM
#4
Thread Starter
Addicted Member
I tried it and it works.
THANKS, PAUL!!!
Zvonko Bostjancic
Ilirska Bistrica, Slovenia
[email protected]
Using VS6 Professional with SP3
Programming mostly in VB and I've started to learn VC++ & MFC
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
|