Home > Blockchain >  how to use hDevMode from PRINTDLGA
how to use hDevMode from PRINTDLGA

Time:04-17

how to cast HGLOBAL to DEVMODE? I tried like this:

PRINTDLG pd;
pd.hDevMode = NULL;
if(PrintDlg(&pd)){
    DEVMODE* test=(DEVMODE*)pd.hDevMode;

CodePudding user response:

Per the PRINTDLGA documentation:

hDevMode

Type: HGLOBAL

A handle to a movable global memory object that contains a DEVMODE structure.

So, use GlobalLock() to access the DEVMODE, eg:

PRINTDLG pd = {};
pd.lStructSize = sizeof(pd);
...

if (PrintDlg(&pd)){
    DEVMODE* test = (DEVMODE*) GlobalLock(pd.hDevMode);
    // use test as needed...
    GlobalUnlock(pd.hDevMode);
    GlobalFree(pd.hDevMode);
}
  • Related