From: JG on
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

//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

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: Gianni Mariani on
JG wrote:
> 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
>
> //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


lpSavCurDevMode seems to be uninitialized. What should be in there ?
From: Daniel T. on
In article <ffn2m902ik8(a)news4.newsguy.com>, "JG" <NoMail(a)NoSpam> wrote:

> 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
>
> //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

lpSavCurDevMode points to an invalid place in memory. You have to
initialize it first.
From: JG on

"Daniel T.">
> lpSavCurDevMode points to an invalid place in memory.
>You have to initialize it first.
-----------------------
Thanks for the reply but is there an easier way to do this
than actually pasting in the entire structure (shown below)
and assigning each variable type a value??
Additionally how would I intialize an array of structures,
this could get quite involved could it not?

typedef struct _devicemodeA {
BYTE dmDeviceName[CCHDEVICENAME];
WORD dmSpecVersion;
WORD dmDriverVersion;
WORD dmSize;
WORD dmDriverExtra;
DWORD dmFields;
union {
struct {
short dmOrientation;
short dmPaperSize;
short dmPaperLength;
short dmPaperWidth;
};
POINTL dmPosition;
};
short dmScale;
short dmCopies;
short dmDefaultSource;
short dmPrintQuality;
short dmColor;
short dmDuplex;
short dmYResolution;
short dmTTOption;
short dmCollate;
BYTE dmFormName[CCHFORMNAME];
WORD dmLogPixels;
DWORD dmBitsPerPel;
DWORD dmPelsWidth;
DWORD dmPelsHeight;
DWORD dmDisplayFlags;
DWORD dmDisplayFrequency;
#if(WINVER >= 0x0400)
DWORD dmICMMethod;
DWORD dmICMIntent;
DWORD dmMediaType;
DWORD dmDitherType;
DWORD dmReserved1;
DWORD dmReserved2;
#if (WINVER >= 0x0500) || (_WIN32_WINNT >= 0x0400)
DWORD dmPanningWidth;
DWORD dmPanningHeight;
#endif
#endif /* WINVER >= 0x0400 */


From: Daniel T. on
"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.