From: Jim Langston on
"JG" <NoMail(a)NoSpam> wrote in message news:ffn2m902ik8(a)news4.newsguy.com...
> Another novice question, exception occurring at depicted location of code
> below,
> appreciate all comments:
>
> //Before calling EnumDisplaySettings, set the dmSize member to
> sizeof(DEVMODE),
> //and set the dmDriverExtra member to indicate the size, in bytes, of the
> additional
> //space available to receive private driver-data.
> DWORD iModeNum = 0; // specifies the graphics mode
> LPDEVMODE lpSavCurDevMode; // saving current mode struct

LPDEVMODE is a pointer. Right now it's pointing... nowhere. Into lala
land.

> //Here I'm tring to assign the value of dmSize to sizeof(DEVMODEW) but
> there is a problem
> lpSavCurDevMode->dmSize = sizeof(DEVMODEW); <-------------this pulls an
> exception

Now you are trying to reference some random piece of memory as the contents
of LPDEVMODE. But it's still pointing nowhere. You'll need to actualy
allocate memory for it. Using malloc (in C) or new (in C++).

The code I've seen using LPDEVMODE uses malloc, although it gets the size
from somewhere else. I would suggest you ask in a microsoft newsgroup or
try to google for a source example of what you are doing.

>
> lpSavCurDevMode->dmDriverExtra = 64;
> LPDEVMODE lpDevMode[10]; //other mode data recieving structs
> BOOL EnumRET;
>
> //Save the Current Device Mode settings,
> // EnumRET = EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS,
> lpSavCurDevMode);
> for (iModeNum = 0; iModeNum <=10; iModeNum = iModeNum + 1)
> {
> EnumRET = EnumDisplaySettings(NULL, iModeNum, lpDevMode[iModeNum]);
> if (EnumRET==0)
> break;
> lpDevMode[iModeNum]->dmSize = sizeof(DEVMODEW);
> lpDevMode[iModeNum]->dmDriverExtra = 64;
> }
>
>


From: JG on

"Jim Langston"
> Now you are trying to reference some random piece of memory as the contents of LPDEVMODE. But
> it's still pointing nowhere. You'll need to actualy allocate memory for it. Using malloc (in C)
> or new (in C++).
>
Thanks for the reply, well I got around having to manually initialize the entire structs
by declaring the struct first for the compiler and then assigning the ptr to it.
Corrective code inserts below. I've may still have some problems somewhere down
the road, but I was able step through this code without an exception this morning
before work. I will step all the way thru the app tonight.

DWORD iModeNum = 0; // specifies the graphics mode
LPDEVMODE lpDevMode[10]; // recieving other mode structs
LPDEVMODE lpSavCurDevMode; // saving current mode struct
//insert test
DEVMODEA SavCurDevMode, DevMode[10]; //<-inserted corrective code
lpSavCurDevMode = &SavCurDevMode; //<-inserted corrective code
//end insert test
lpSavCurDevMode->dmSize = sizeof(DEVMODEW);
lpSavCurDevMode->dmDriverExtra = 64;
DWORD MatchMode;
BOOL EnumRET;

//Save the Current Device Mode settings,
EnumRET = EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, lpSavCurDevMode);
for (iModeNum = 0; iModeNum <=10; iModeNum = iModeNum + 1)
{
lpDevMode[iModeNum] = &DevMode[iModeNum]; //<-inserted corrective code
lpDevMode[iModeNum]->dmSize = sizeof(DEVMODEW);
lpDevMode[iModeNum]->dmDriverExtra = 64;
EnumRET = EnumDisplaySettings(NULL, iModeNum, lpDevMode[iModeNum]);
if (EnumRET==0)
break;
}

> The code I've seen using LPDEVMODE uses malloc, although it gets the size from somewhere else. I
> would suggest you ask in a microsoft newsgroup or try to google for a source example of what you
> are doing.
>


From: Francis Glassborow on
Daniel T. wrote:
> "JG" <NoMail(a)NoSpam> wrote:
>
>> ...is there an easier way to do this than actually pasting in the
>> entire structure (shown below) and assigning each variable type a
>> value?
>
> Every variable in a program has to have a valid value before it can be
> used constructivly. Some value that is useful in the context of that
> variable. What you ask is like asking if you can build a car without
> bothering to make sure that the nuts fit the bolts.
>
>> Additionally how would I intialize an array of structures, this
>> could get quite involved could it not?
>
> Generally, arrays are created because they all, in some sense, can be
> treated the same. So write loops that go through each of the variables
> in the array and assign them a useful value.


Or simply zero initialise them:

int i[1000] = {0};

Now all the values are initialised and you can pick when to change the
stored value to something other than 0.

You can do something similar with structs


--
Note that robinton.demon.co.uk addresses are no longer valid.