How can I copy binary data created by GlobalAlloc to the clipboard


Hi,

I created binary data with GlobalAlloc, but I don't know how to put it on the clipboard. Here is my code:

---------------------------------------------------------------------------------------------------------------------------------------
    Dim lngMemory_handle As Long
    Dim lngMemory_pointer As Long

    Dim lngRead As Long
    Dim hFile As Long

    lngMemory_handle = GlobalAlloc(GMEM_MOVEABLE, LOF(m_FileNumber))
   
    If lngMemory_handle Then

        ' Lock the memory while we initialize it.
        lngMemory_pointer = GlobalLock(lngMemory_handle)

        hFile = CreateFile(FileName, GENERIC_READ, FILE_SHARE_READ, ByVal 0&, OPEN_EXISTING, FILE_ATTRIBUTE_ARCHIVE, ByVal 0&)

        lngRead = lread(hFile, ByVal lngMemory_pointer, LOF(m_FileNumber))

        lngRead = CloseHandle(hFile)

    End If
   
    GlobalUnlock lngMemory_handle

---------------------------------------------------------------------------------------------------------------------------------------r

Now how can I copy data pointed by lngMemory_pointer to the clipboard?



Thanks
TungVanAsked:
Who is Participating?
 
AzraSoundCommented:
Initial thought would be:

CopyMemory to move data into byte array from pointer
StrConv to copy byte array into a string
Move string to clipboard


So, something like:

Dim b() As Byte
Dim s As String

Redim b(1 To DataLength) As Byte
CopyMemory b(1), lngMemory_pointer, DataLength
s = StrConv(b, vbUnicode)
Clipboard.SetText s
0
 
PaulHewsCommented:
Once again, it wouldn't hurt to know what you were trying to do, because there are probably easier ways of doing it.  You might consider letting us know in your other question as well.
0
 
AzraSoundCommented:
Thanks!   ;-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.