setmode again
Brian Myers
bmyers at harryanddavid.com
Thu Aug 7 15:36:20 PDT 2008
Hi all,
Seems this gets revisited every so often on the forums, so I guess it's time to visit it again...
I need to set stdout to binary mode in Windows. I've tried the following:
import std.string;
import std.stdio;
import std.c.windows.windows;
extern (C)
alias int function(int,int) setmode_f;
void main(char[][] args)
{
int O_BINARY = 0x8000;
setmode_f f;
HMODULE m = cast(HMODULE) LoadLibraryA(toStringz("msvcrt.dll"));
f = cast(setmode_f) GetProcAddress(m, toStringz("_setmode"));
f(fileno(stdout), O_BINARY);
writef("test line1\r\ntestline2");
}
and
import std.string;
import std.stdio;
extern (C)
alias int function(int,int) setmode_f;
extern ( C ) int setmode(int,int);
void main(char[][] args)
{
int O_BINARY = 0x8000;
if (setmode(fileno(stdout) ,O_BINARY) < 0)
writefln("setmode failed.");
writef("test line1\r\ntest line2");
}
No luck. Both compile and run without error, but Windows is still doing LF->CRLF translation.
I know I need a version statement for a cross platform compile, but this is just example code.
Brian
More information about the Digitalmars-d
mailing list