Skip to main content
gamedev.net
🔒 Locked

Simple pointer problem

Started by LaBasX2 4 replies 350+ views
Original Post
LaBasX2
LaBasX2
Hi! I''ve got a little newbie problem. void *bits; BYTE *pixels; I need to create the pointer pixels so that I can access the bits array. For example I want to write: pixels[0] = 255; or *pixels[0] = 255; don''t know How do I have to init pixels now? pixels = (BYTE*) bits; or how else? Can anyone please help me. Thanks cu
LaBasX2
LaBasX2
Thanks, but I don't want to create a new array.

What I want is the following:

When I change the value of pixels, the value of the memory
which is associated with bits needs to be changed, too.

So pixels is a pointer on the bits pointer, but how do I
convert it from void to BYTE?

Edited by - LaBasX2 on September 9, 2000 7:21:55 PM
Cel
Cel
Why have you declared the bits variable as void?

I am guessing so you could try and use either byte or word size pointers.

I dont think you will be able to access an array of ''void'' data elements using a pointer like that.

You might wanna consider have like this:

BYTE *bits;

BYTE *pixels;

after the bits pointer points to a valid chunk of BYTE data, you should be able to use pixels[0] etc to access the memory space of each BYTE. I think to change a value at a position you could use

pixels = &(bits[0]);
*pixels = 255;

In this way, if you needed to step through the bits array using the pixels pointer, you could just iterate the line

pixels++;

this will advance the pointer by sizeof(BYTE), because that is the data type of the pointer.

This is from memory so I could be a bit off track.

Cel
Cel aka Razehttp://chopper2k.qgl.org
Cel
Cel
Oops, typo there

''you should be able to use pixels[0] etc to access the memory''

I meant bits[0] etc

Cel
Cel aka Razehttp://chopper2k.qgl.org
LaBasX2
LaBasX2
Thanks for your reply.

I want to use ''CreateDIBSection'' and this routine needs a void
pointer. Now I want to access this DIB and somehow I need a
BYTE-pointer, or don''t I need one? I don''t know, I''m new to VC!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.