Clipboard's Memory

Posted on 2007-08-10
Last Modified: 2010-04-30
Hi :)

How can I read the clipboard's memory directly? e.g. there is a BMP in the clipboard & i would like to read some bytes of that BMP directly from the memory without saving that BMP to harddrive nor pasting that BMP to a picturebox. I'm using VisualBasic
Question by:martymane
    LVL 38

    Accepted Solution

    Option Explicit

    Private Type BITMAP
        bmType As Long
        bmWidth As Long
        bmHeight As Long
        bmWidthBytes As Long
        bmPlanes As Integer
        bmBitsPixel As Integer
        bmBits As Long
    End Type
    Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
    Private Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long

    Private Sub Command1_Click()
        Dim b() As Byte
        Dim bmp As BITMAP
        Dim i As Long, BytesPerLine As Long

        Dim pic As StdPicture
        Set pic = Clipboard.GetData
        GetObject pic, Len(bmp), bmp
        BytesPerLine = (bmp.bmWidth * 3 + 3) And &HFFFFFFFC
        ReDim b(1 To BytesPerLine * bmp.bmHeight * 3) As Byte
        GetBitmapBits pic, UBound(b), b(1)  
        'All bitmap bytes are now in the array...
        For i = 1 To 100
            Debug.Print b(i)

    End Sub

    Author Comment

    EXCELLENT :) & so fast

    1 last question though.
    Is it possible to read those values (pixels) in memory using offsets & without assingning them to an array?
    Just to make it faster
    LVL 38

    Expert Comment

    I've never tried it myself, but you can try the technique mentioned here:

    Author Comment

    Great service!

    Big THX Paul

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
    The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
    The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now