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 175573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:43:23+00:00 2026-05-11T13:43:23+00:00

I’ve got an old app that I need to get to print in landscape

  • 0

I’ve got an old app that I need to get to print in landscape mode. The documentation I’ve found says to get a DEVMODE structure, change a couple of fields, and put it back in. What I’ve got is:

    HANDLE printer_handle;     LPHANDLE printer_handle_pointer(&printer_handle);     OpenPrinter(printer_name.get(), printer_handle_pointer, NULL);     size_t devmode_size = DocumentProperties(hWnd, printer_handle_pointer, printer_name.get(), NULL, NULL, 0);     DEVMODE * devmode = reinterpret_cast<DEVMODE *>(new char[devmode_size]);     DocumentProperties(NULL, printer_handle_pointer, printer_name.get(), devmode, NULL, DM_OUT_BUFFER);     devmode->dmSize = sizeof( DEVMODE);     devmode->dmFields |= DM_ORIENTATION;     devmode->dmOrientation = DMORIENT_LANDSCAPE;     DocumentProperties(NULL, printer_handle_pointer, printer_name.get(), devmode, devmode, DM_IN_BUFFER | DM_OUT_BUFFER);     hdcPrint = CreateDC(NULL, printer_name.get(), NULL, devmode); 

My current problem is that the first DocumentProperties (the one that returns the size of the DEVMODE structure) is returning a -1 (actually the unsigned equivalent), signifying an error condition. This happens in both Debug and Release mode (one report I saw on the web had this problem in Debug but not Release). The printer_name.get() is valid, but I don’t know how to check the hWnd or printer_handle_pointer for correctness in the debugger.

So, I’d like it if somebody could tell me what I’m doing wrong, or how to diagnose it better, or how to tell if the handles are valid and point to valid information, I’d appreciate it.

I’m using VS 2008SP1 on Vista Business SP1, if that makes any difference. The original app was written with an earlier version of VS on some version of XP.

  • 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. 2026-05-11T13:43:24+00:00Added an answer on May 11, 2026 at 1:43 pm

    Have you posted the real code?

    Also, take a look at the DocumentProperties function signature:

    LONG DocumentProperties(      __in   HWND hWnd,      __in   HANDLE hPrinter,               __in   LPTSTR pDeviceName,      __out  PDEVMODE pDevModeOutput,      __in   PDEVMODE pDevModeInput,      __in   DWORD fMode 

    The third parameter takes a HANDLE and not a pointer to a HANDLE (or LPHANDLE) as you have in your code:

    DocumentProperties(NULL,                     printer_handle_pointer, /* <--- ? */                    printer_name.get(),                     devmode,                     NULL,                     DM_OUT_BUFFER); 

    Use instead:

    DocumentProperties(NULL,                     printer_handle, /* <--- ? */                    printer_name.get(),                     devmode,                     NULL,                     DM_OUT_BUFFER); 

    Take a look at this sample code to modify Devmode using DocumentProperties function.

    I typically use GetPrinterW to get a PRINTER_INFO_2W structure. The pDevMode member returns you the devmode. I have had some luck using this devmode.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters

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.