1. C structs & bad aftershave...

Ok no Old Spice... I just wanted some attention! :)

Background: Lest I get ahead of myself.
I am using M Akita's SDL for Eu wrapper. SDL is compiled into a DLL.
I want to access a member of a C structure. 

typedef struct{
  Uint32 hw_available:1;
  Uint32 wm_available:1;
  Uint32 blit_hw:1;
  Uint32 blit_hw_CC:1;
  Uint32 blit_hw_A:1;
  Uint32 blit_sw:1;
  Uint32 blit_sw_CC:1;
  Uint32 blit_sw_A:1;
  Uint32 blit_fill;
  Uint32 video_mem;
  SDL_PixelFormat *vfmt;
} SDL_VideoInfo;

I can access its value by doing this:

atom videoInfo

videoInfo = SDL_GetVideoInfo()

How do I, using Euphoria, best go about reading the above bit flags?
I have tried this:

<EuCode)
sequence mbits
atom lflg

mbits = int_to_bits(videoInfo)

sprintf("flags: %d %d %d ...<snip>", {mbits[1], mbits[2], ...<snip>})

<EuCode>

Which gives me some really odd results.  When I peek 36 bytes into this 
structure, and grab 4 bytes, I do get the correct amount of video memory 
for my graphics card.  There ends my success though.

Could someone explain to me how to access the bit flags of that struct?
I seem to be doing this all wrong despite my best intentions. :)

For more info, here is the SDL API page.
http://www.libsdl.org/cgi/docwiki.cgi/SDL_20API

Thanks again. As always, you guys rule.

new topic     » topic index » view message » categorize

2. Re: C structs & bad aftershave...

> Does that look correct?

Isn't videoinfo a pointer to a structure? You're gonna get some really
odd results if you do and_bits() on a pointer, it will almost always
be a different value. You have to first peek or fetch the value from
memory. Have you looked into tk_mem or Win32Lib's built-in structure
handling? It really helps out a lot.

~Greg

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu