[RESOLVED] Copymem API Error - wierd one ????
Now this is a very wierd problem...
Code:
Private Block As String
Private File_Block As Long
Private Sub MoveData ()
Dim arr_dat() As Byte
Get_Data () ' Function that returns 1024 bytes in Arr_dat..
File_block = 1024
Block = Space(1024)
CopyMemory Block, arr_dat(0), File_Block ' this now shuts down the IDE...
End Sub
the CopyMemory API causes the ide to exit ...
I'm trying to move and array of binary data into a string without resorting to a loop... And this one has me going mad...
Any Advice ???
Gremmy....
Re: Copymem API Error - wierd one ????
Use this:
StringVariable = StrConv(ByteArray, vbUnicode)
Re: Copymem API Error - wierd one ????
well, each character of a string is two bytes, not one - so the string has to be half the size of the byte array. You also need to pass the memory location of the String's byte array, rather than the BSTR:
Code:
Block = Space(1024 \ 2)
CopyMemory ByVal StrPtr(Block), arr_dat(0), File_Block
that now won't crash your IDE, but it may not be what you're intending to achieve. You may want what logophobic posted, or perhaps even a simple:might achieve your needs...
Re: Copymem API Error - wierd one ????
or you may just specify byval to the string variable (Block).
CopyMemory ByVal Block, arr_dat(0), File_Block
Re: Copymem API Error - wierd one ????
Quote:
Originally Posted by Logophobic
Use this:
StringVariable = StrConv(ByteArray, vbUnicode)
Thanks LogoPhobic...
This works great .. Duno why i didn't remember the function....
Reps when i can give again...
Gremmy
Re: Copymem API Error - wierd one ????
hi Gremmy,
perhaps we have different declaration of the Copymemory. the following code works well on my computer :)
Code:
Option Explicit
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
Private Sub Command1_Click()
Dim s$, b() As Byte
b = StrConv("one last breath", vbFromUnicode)
s = Space$(UBound(b) + 1)
CopyMemory ByVal s, b(0), Len(s)
MsgBox s
End Sub
:wave:
Re: Copymem API Error - wierd one ????
Thread1..
I have it declared the same way..
Code:
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
And for some reason it closes the IDE down - No error msg, no nothing...
Dunno why.. at a later stage i will look at it again and try it again..
Gremmy...
Re: Copymem API Error - wierd one ????
ok.. let me say the word again "weird" .. yeah that's weird :D :wave: