Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8295983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:48:02+00:00 2026-06-08T14:48:02+00:00

The following compiles without errors or warnings but doesn’t snag the IEFrame window, or

  • 0

The following compiles without errors or warnings but doesn’t snag the IEFrame window, or at least I know it fails to change that window’s print orientation to landscape:

PRINTDLGEX pd;
pd.lStructSize = (DWORD)sizeof(PRINTDLG);    
BOOL GetPrinterDeviceDefaults(struct tagPDA* pd);

BOOL bRet=AfxGetApp()->GetPrinterDeviceDefaults(&pd); 
pd.hwndOwner = FindWindow("IEFrame", NULL);
LPDEVMODE pDevMode = (LPDEVMODE)::GlobalLock(&pd.hDevMode);
pDevMode->dmOrientation = DMORIENT_LANDSCAPE;
::GlobalUnlock(&pd.hDevMode);

I have evidence the code may have acquired the hWnd of the IEFrame window because the results of MessageBox(0,(LPCSTR)pd.hwndOwner,"[header]",MB_OK); displays some text gobbledygook in the msg. instead of nothing.

Thanks for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T14:48:03+00:00Added an answer on June 8, 2026 at 2:48 pm

    I’m not at all familiar with the PRINTDLG API you’re trying to use, but your MessageBox code is all wrong.

    The MessageBox function takes two pointers to null-terminated C strings (either ANSI strings or Unicode strings, depending on whether UNICODE is defined by the preprocessor). You’re passing in a window handle instead, which is not a null-terminated C string of any type — it’s just an opaque data value that only has meaning to the kernel. So when MessageBox tries to interpret the string, it gets a pointer to who-knows-where, and it will either crash with an access violation or read random gobbledygook out of memory until it runs into a stray NUL byte.

    Ordinarily the compiler will give you an error here, but by inserting the cast you’re telling “it’s OK, I know what I’m doing, I promise this is really an LPCTSTR“, which masks the error.

    The correct fix to this is to print the handle value into a character array. For example:

    #define DIM(x) (sizeof(x)/sizeof((x)[0]))
    wchar_t handleStr[64];
    _snprintf_s(handleStr, DIM(handleStr), _TRUNCATE, "Handle value: %p", (void*)pd.hwndOwner);
    MessageBoxW(NULL, handleStr, L"[header]", MB_OK);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following two code snippets compiles without any errors/warnings but while running it crashes.
I know unsigned int can't hold negative values. But the following code compiles without
The following code compiles in Visual C++ and gcc, but fails with Code Warrior
I have a file which compiles without errors or warnings on my macbook pro
I have following piece of code: It compiles without problems under gcc-3.4, gcc-4.3, intel
The following compiles fine: Object o = new Object(); System.out.println(o instanceof Cloneable); But this
the following code compiles with Visual Studio 2008 but not with g++ on Mac
The following simple piece of code, compiles with VC2008 but g++ rejects the code:
Given the generic method: <T> List<T> getGenericList(int i) {...} the following code compiles without
Consider the following code: int main() { int *p; ++((int){5}); //compile without err/warning &((int){5});

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.