Author Topic: How to statically init DEVMODE structure?  (Read 6303 times)

0 Members and 1 Guest are viewing this topic.

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
How to statically init DEVMODE structure?
« on: October 24, 2007 »
Help!

I am sadly failing in VC++ Express to statically initialise with values filled in the following structure:

http://msdn2.microsoft.com/en-us/library/ms535771.aspx

I want to do something like:

static DEVMODE dmScreenSettings={
(BCHAR)NULL, //device name
(WORD)0, //spec version
(WORD)0, // driver version
(WORD)sizeof(dmScreenSettings),
...
..

but I cant get it to work. Can anyone provide a quick example?
A web search didnt reveal much.

I should add, under XP/Vista!

Chris

« Last Edit: October 24, 2007 by chris »
Challenge Trophies Won:

Offline ahayweh

  • ZX 81
  • *
  • Posts: 4
  • Karma: 1
    • View Profile
Re: How to statically init DEVMODE structure?
« Reply #1 on: October 24, 2007 »
What errors are you getting? Using the method  you are using, you *have* to intialize all members of the DEVMODE struct. If you only want to  init certain members, just use the member access operator.

Here is a rip from an old engine of mine :

pOGL is a pointer to a OpenGL interface struct.

DEVMODE dmScreenSettings;

memset(&dmScreenSettings , 0 , sizeof(dmScreenSettings));

dmScreenSettings.dmSize=sizeof(dmScreenSettings);   
dmScreenSettings.dmPelsWidth   = pOGL->contextPitch;         
dmScreenSettings.dmPelsHeight   = pOGL->yResolution;         
dmScreenSettings.dmBitsPerPel   = pOGL->contextDepth;            
dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: How to statically init DEVMODE structure?
« Reply #2 on: October 24, 2007 »
ahayweh,

I want to do it statically and assign all relevant members, *not* at run time. My errors are:

.\Main.cpp(95) : warning C4305: 'initializing' : truncation from 'DWORD' to 'BYTE'
.\Main.cpp(95) : warning C4309: 'initializing' : truncation of constant value
.\Main.cpp(104) : warning C4309: 'initializing' : truncation of constant value
.\Main.cpp(105) : warning C4309: 'initializing' : truncation of constant value

Chris
Challenge Trophies Won:

Offline stormbringer

  • Time moves by fast, no second chance
  • Amiga 1200
  • ****
  • Posts: 453
  • Karma: 73
    • View Profile
    • www.retro-remakes.net
Re: How to statically init DEVMODE structure?
« Reply #3 on: October 24, 2007 »
looks more like warnings because of type casting rather than errors...
We once had a passion
It all seemed so right
So young and so eager
No end in sight
But now we are prisoners
In our own hearts
Nothing seems real
It's all torn apart

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: How to statically init DEVMODE structure?
« Reply #4 on: October 24, 2007 »
looks more like warnings because of type casting rather than errors...

Yes I know, but I have cast to the correct types. No something else is wrong in what I'm doing.

Aha! It doesnt work yet but I got rid of the errors:

static DEVMODE dmScreenSettings={
(BCHAR)NULL, //device name

Should be

static DEVMODE dmScreenSettings={
(BCHAR)"", //device name

Chris
« Last Edit: October 24, 2007 by chris »
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: How to statically init DEVMODE structure?
« Reply #5 on: October 24, 2007 »
Man!  Device name is an array!!
So it needs a CCHDEVICENAME-long initializer.  Something of type char[CCHDEVICENAME].  Null won't work.  (BCHAR)"" is hopeful :)
Take out ALL the casts, and then fix them on a case-by-case basis.  With the casts in there you're lieing to yourself and the compiler.

Jim
Challenge Trophies Won:

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: How to statically init DEVMODE structure?
« Reply #6 on: October 24, 2007 »
Aha, cracked it!

static DEVMODE dmScreenSettings={
"",0,0,
(WORD)sizeof(dmScreenSettings),
0,
DM_PELSWIDTH|DM_PELSHEIGHT,
0,0,0,0,0,0,0,0,0,0,0,0,0,
"",
0,0,
1024,
768,
0,0,0,0,0,0,0,0,0,0};

...it was those "" quotes that were killing me. OK incase you are wondering, this is all about crunching a few more bytes from 1k frameworks. Thanks to those who tried to help.

Chris
Challenge Trophies Won: