Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2005-05-11
4
Medium Priority
?
422 Views
Last Modified: 2012-06-22

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
0
Comment
Question by:TungVan
  • 2
3 Comments
 
LVL 28

Accepted Solution

by:
AzraSound earned 1000 total points
ID: 13978576
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
 
LVL 38

Expert Comment

by:PaulHews
ID: 13982097
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
 
LVL 28

Expert Comment

by:AzraSound
ID: 14026913
Thanks!   ;-)
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month10 days, 1 hour left to enroll

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question