how can i use CopyMemory() on VB6?
i have these funcion:

Public Sub Clear(BGRColor As Long)
    Dim i As Long
    For i = 0 To (Width * Height) - 1
        CopyMemory ByVal PixelData(0) + (i * 4), vbGreen, 4
    Next i
End Sub

how can avoid the 'for' loop?
i tried:

Public Sub Clear2(BGRColor As Long)
    Dim i As Long
    i = ((Width * Height) - 1) * 4
    CopyMemory ByVal PixelData(0), vbGreen, i
End Sub

but seems that i fail on 'i' calculation(array size)... maybe because we have 4 bytes by a pixel?

the BitBlt() is for draw the image from 1 HDC to another HDC.

on VB6 is more hard to use pointers.. it's possible, i know that, because i'm doing it, but we must know what we are doing, because it's pointers(like Multithread)...
but how can i fill a memory pointer that have 4 bytes by a pixel?(RGBA)

commented: Remember that few of us have VB6 anymore. We'll have to rely on other discussions. +17

thank you so much for all to all

commented: In the future, reveal what the goal is. I am left to guess what you are trying to do overall. +0

rproffitt my big goal, like others topics\questions, is using DIB's on VB6... but the pixel data be a pointer for change the pixel, using the pixel data array, directly on HDC\HBITMAP.
theres some ways:
but i need learn use it. thanks for all

Working with pointers in VB6 can be more challenging, but it's certainly possible. It requires a thorough understanding of the concept, as dealing with pointers is akin to managing multithreading – precise knowledge is key. However, I'm intrigued by a specific aspect: how to effectively populate a memory pointer that accommodates 4 bytes for each pixel (representing RGBA). This indicates a nuanced exploration of memory management within VB6, demonstrating an advanced level of expertise. Could you kindly share your insights on accomplishing this task? Your experience could greatly benefit those navigating similar complexities.

i need some time.. but i will share it ;)

Well, script that you have tries have some issue, can you try below script.

   Public Sub Clear2(BGRColor As Long)
        Dim i As Long
        Dim dataSize As Long

        ' Calculate the total size of the array in bytes
        dataSize = (Width * Height) * 4

        ' Use CopyMemory to fill the entire array with the specified color
        CopyMemory ByVal PixelData(0), ByVal VarPtr(BGRColor), dataSize
    End Sub


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.