setmode again

Brian Myers bmyers at harryanddavid.com
Fri Aug 8 17:22:44 PDT 2008


Ok, here's the current version I tried:

import std.string;
import std.stdio;
import std.c.windows.windows;

extern (Windows)
alias int function(int,int) setmode_f;

//extern ( C ) int setmode(int,int);

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"));
    if (f(fileno(stdout), O_BINARY) < 0)
        writefln("setmode failed.");

//    if (setmode(fileno(stdout) ,O_BINARY) < 0)
//        writefln("setmode failed.");
    writef("test line1\r\ntestline2\n");
}

No dice. Still doing CR/LF translation.

Steven Schveighoffer Wrote:

> "Brian Myers" wrote
> > No, I haven't because I thought that would result in a compiler or linker 
> > error. What happens is the function is executed at run time, but has no 
> > effect. I think I have a better idea now thought:
> 
> Try the extern(Windows).  The difference is the call stack layout.  what 
> could be happening is you are calling a function one way, but the function 
> expects to be called a different way.  So it isn't reading the parameters 
> like you think it is (in fact, it might be reading garbage).
> 
> You won't get a compiler or linker error because you are not linking the 
> function in, you are dynamically loading it.
> 
> -Steve 
> 
> 




More information about the Digitalmars-d mailing list