ramneek.kochhar
July 13th, 2009, 04:19 AM
hi,
i have a basic question about the usage of GlobalLock() API.
As far as i know i have used it along with GlobalAlloc() and GlobalUnlock() in the following manner.
{.
.
HGLOBAL m_hDevMode= GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
DEVMODE *pDevMode = (DEVMODE *)GlobalLock(m_hDevMode);
memset(pDevMode, 0, sizeof(DEVMODE));
GlobalUnlock(m_hDevMode);
.
.}
but what if i use it with compiler memory management operators i.e. malloc and new.
i have the following code snippet.
{.
.
m_pDlgPageSetup = new PAGESETUPDLG; //standard PAGESETUPDLG structure of windows
ZeroMemory(m_pDlgPageSetup, sizeof(*m_pDlgPageSetup));
.
.}
{.
.
m_pDlgPageSetup->hDevMode = (HANDLE)NULL;
LPDEVMODE lpOutpmode = (LPDEVMODE)GlobalLock(m_pDlgPageSetup->hDevMode);
.
.}
is the above implementation fine??
if not then how shold i go around to get a pointer to a memory block allocated with new?? or can i access the HANDLE directly as a pointer since its not private to the process.
<all the above functions are in a single file which manages the printer for my application>
Thanks.
i have a basic question about the usage of GlobalLock() API.
As far as i know i have used it along with GlobalAlloc() and GlobalUnlock() in the following manner.
{.
.
HGLOBAL m_hDevMode= GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
DEVMODE *pDevMode = (DEVMODE *)GlobalLock(m_hDevMode);
memset(pDevMode, 0, sizeof(DEVMODE));
GlobalUnlock(m_hDevMode);
.
.}
but what if i use it with compiler memory management operators i.e. malloc and new.
i have the following code snippet.
{.
.
m_pDlgPageSetup = new PAGESETUPDLG; //standard PAGESETUPDLG structure of windows
ZeroMemory(m_pDlgPageSetup, sizeof(*m_pDlgPageSetup));
.
.}
{.
.
m_pDlgPageSetup->hDevMode = (HANDLE)NULL;
LPDEVMODE lpOutpmode = (LPDEVMODE)GlobalLock(m_pDlgPageSetup->hDevMode);
.
.}
is the above implementation fine??
if not then how shold i go around to get a pointer to a memory block allocated with new?? or can i access the HANDLE directly as a pointer since its not private to the process.
<all the above functions are in a single file which manages the printer for my application>
Thanks.