Author Topic: Print dialog in Debug build  (Read 3229 times)

Offline rlb

  • Multiple posting newcomer
  • *
  • Posts: 14
Print dialog in Debug build
« on: August 30, 2016, 01:49:57 pm »
I use the PrintDlg() common dialog in my program (I know, I should use PrintDlgEx, but that doesn't compile at all and that's another subject which may be a MinGW problem), and the Release build works fine. The Debug build, though, does not. It refuses to link, says that PrintDlgA is undefined.
Now, I think I know what the problem is: that function is only defined for full GUI applications, not for console applications, not even ones which immediately fire up the GUI portion of the program. Fair enough, and not a Code::Blocks problem. However, I really would like my Debug build to fire up a console so I can use printf() for quick debugging messages, I find that a much more efficient way to see what goes wrong than going through GDB every time.

My questions are this:

- Am I right in my suspicion about the cause of the problem?
- Is there a way to kick Windows so that it allows a console application to use _all_ Common Dialogs including PrintDlg()?

and the Code::Blocks proper part of the question:

- If not, is there an option I can set to convince Code::Blocks, or to get it to convince MinGW, to give me a console window after all within my GUI application? There's a lot of options...

(Standard C::B installation, by the way - 16.01, MinGW 4.9, no other implementations installed; Win7 Pro, if that matters.)
Richard Bos

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Print dialog in Debug build
« Reply #1 on: August 30, 2016, 08:30:25 pm »
Yes, it is possible to have a console in a GUI app, but you have to show it manually with code.
Search for AllocConsole or AttachConsole or something similar, don't remember the exact call.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline rlb

  • Multiple posting newcomer
  • *
  • Posts: 14
Re: Print dialog in Debug build
« Reply #2 on: September 02, 2016, 10:10:27 am »
Right... but then I'd have to do that only in the debug build. I gather Code::Blocks doesn't #define DEBUG automatically, but I can set that in the build options. However, when I try that, it does show a console window... but it doesn't show stdio output. Drat. I'll have to investigate further.
At first I thought typicalc's solution in the Help forum ("console for raspberry") would help, but that has the same problem. I can set that option - I didn't know it was there, but it was, under Windows as well - and it does start a console, but it doesn't seem to receive stdio output.
Richard Bos

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Print dialog in Debug build
« Reply #3 on: September 02, 2016, 11:53:58 pm »
I gather Code::Blocks doesn't #define DEBUG automatically, but I can set that in the build options. However, when I try that, it does show a console window...
This is up to you. Code::Blocks is just the UI you're using to setup and build your project.

but it doesn't show stdio output. Drat. I'll have to investigate further.
You have to redirect some handles to the new console. There are plenty of examples in the net. Just search for them.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline rlb

  • Multiple posting newcomer
  • *
  • Posts: 14
Re: Print dialog in Debug build
« Reply #4 on: September 05, 2016, 02:40:26 pm »
I gather Code::Blocks doesn't #define DEBUG automatically, but I can set that in the build options. However, when I try that, it does show a console window...
This is up to you. Code::Blocks is just the UI you're using to setup and build your project.
Certainly. But as CB does create a Release and Debug build automatically, I wouldn't have been surprised if it did. No big deal.

but it doesn't show stdio output. Drat. I'll have to investigate further.
You have to redirect some handles to the new console. There are plenty of examples in the net. Just search for them.
That's precisely what I meant by "investigate further", yes.

FTR, adding freopen("CONOUT$", "w", stdout); after AllocConsole(); did it for me. Not at all sure if this is a universal solution, but it's enough for what I want from it.
Richard Bos