Dark Bit Factory & Gravity
PROGRAMMING => C / C++ /C# => Topic started by: taj 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
-
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;
-
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
-
looks more like warnings because of type casting rather than errors...
-
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
-
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
-
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