www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to force console

reply Everlast <Everlast For.Ever> writes:
I can create a console for a dll using AllocConsole and special 
Write functions but this is a pain. How do I get all standard 
input and output to either use this console or for the app to 
create the console automatically?

The problem I'm having is that I can write(using custom write) 
but can't read. I'd rather just have a dll with a normal console 
window like a normal program.

I do have `-L/SUBSYSTEM:CONSOLE`

but no console appears.
Aug 01 2018
parent reply Mike Parker <aldacron gmail.com> writes:
On Wednesday, 1 August 2018 at 20:57:30 UTC, Everlast wrote:
 I can create a console for a dll using AllocConsole and special 
 Write functions but this is a pain. How do I get all standard 
 input and output to either use this console or for the app to 
 create the console automatically?

 The problem I'm having is that I can write(using custom write) 
 but can't read. I'd rather just have a dll with a normal 
 console window like a normal program.

 I do have `-L/SUBSYSTEM:CONSOLE`

 but no console appears.
As far as I know, that only works with executables. Loading a DLL does not trigger the opening of a console. You'll have to stick with AllocConsole and redirect the I/O. http://www.asawicki.info/news_1326_redirecting_standard_io_to_windows_console.html
Aug 01 2018
parent reply Everlast <Everlast For.Ever> writes:
On Thursday, 2 August 2018 at 03:20:30 UTC, Mike Parker wrote:
 On Wednesday, 1 August 2018 at 20:57:30 UTC, Everlast wrote:
 I can create a console for a dll using AllocConsole and 
 special Write functions but this is a pain. How do I get all 
 standard input and output to either use this console or for 
 the app to create the console automatically?

 The problem I'm having is that I can write(using custom write) 
 but can't read. I'd rather just have a dll with a normal 
 console window like a normal program.

 I do have `-L/SUBSYSTEM:CONSOLE`

 but no console appears.
As far as I know, that only works with executables. Loading a DLL does not trigger the opening of a console. You'll have to stick with AllocConsole and redirect the I/O. http://www.asawicki.info/news_1326_redirecting_standard_io_to_windows_console.html
Thanks, but does that work in D? Error: cannot cast expression `*fp` of type `shared(_iobuf)` to `File*`
Aug 02 2018
parent reply Simen =?UTF-8?B?S2rDpnLDpXM=?= <simen.kjaras gmail.com> writes:
On Thursday, 2 August 2018 at 12:08:50 UTC, Everlast wrote:
 On Thursday, 2 August 2018 at 03:20:30 UTC, Mike Parker wrote:
 On Wednesday, 1 August 2018 at 20:57:30 UTC, Everlast wrote:
 I can create a console for a dll using AllocConsole and 
 special Write functions but this is a pain. How do I get all 
 standard input and output to either use this console or for 
 the app to create the console automatically?

 The problem I'm having is that I can write(using custom 
 write) but can't read. I'd rather just have a dll with a 
 normal console window like a normal program.

 I do have `-L/SUBSYSTEM:CONSOLE`

 but no console appears.
As far as I know, that only works with executables. Loading a DLL does not trigger the opening of a console. You'll have to stick with AllocConsole and redirect the I/O. http://www.asawicki.info/news_1326_redirecting_standard_io_to_windows_console.html
Thanks, but does that work in D? Error: cannot cast expression `*fp` of type `shared(_iobuf)` to `File*`
I tried getting it to work, gave up, and found some example code that I boiled down to this: import std.stdio : writeln, stdout; AllocConsole(); freopen("CON", "w", stdout.getFP); writeln("OHAI!"); That works on my machine, but I haven't read enough to know why it wouldn't fail on others. -- Simen
Aug 02 2018
parent reply Everlast <Everlast For.Ever> writes:
On Thursday, 2 August 2018 at 13:02:21 UTC, Simen Kjærås wrote:
 On Thursday, 2 August 2018 at 12:08:50 UTC, Everlast wrote:
 On Thursday, 2 August 2018 at 03:20:30 UTC, Mike Parker wrote:
 On Wednesday, 1 August 2018 at 20:57:30 UTC, Everlast wrote:
 I can create a console for a dll using AllocConsole and 
 special Write functions but this is a pain. How do I get all 
 standard input and output to either use this console or for 
 the app to create the console automatically?

 The problem I'm having is that I can write(using custom 
 write) but can't read. I'd rather just have a dll with a 
 normal console window like a normal program.

 I do have `-L/SUBSYSTEM:CONSOLE`

 but no console appears.
As far as I know, that only works with executables. Loading a DLL does not trigger the opening of a console. You'll have to stick with AllocConsole and redirect the I/O. http://www.asawicki.info/news_1326_redirecting_standard_io_to_windows_console.html
Thanks, but does that work in D? Error: cannot cast expression `*fp` of type `shared(_iobuf)` to `File*`
I tried getting it to work, gave up, and found some example code that I boiled down to this: import std.stdio : writeln, stdout; AllocConsole(); freopen("CON", "w", stdout.getFP); writeln("OHAI!"); That works on my machine, but I haven't read enough to know why it wouldn't fail on others. -- Simen
Thanks, seems to work. I have to do input too, hopefully it is as simple, as this seems to work: freopen("CON", "r", stdin.getFP); But, when I put this stuff in a static this in a windowsx64 dll, the static this is called about 100 times!!! Not once!
Aug 02 2018
parent Adam D. Ruppe <destructionator gmail.com> writes:
On Thursday, 2 August 2018 at 13:11:20 UTC, Everlast wrote:
 But, when I put this stuff in a static this in a windowsx64 
 dll, the static this is called about 100 times!!! Not once!
try shared static this() instead of just static this() the latter is called once per thread, the former once per process. that might be the difference. maybe. 100 times still seems crazy.
Aug 02 2018