D with CygWin
unDEFER via Digitalmars-d
digitalmars-d at puremagic.com
Sun Dec 4 07:10:26 PST 2016
I have found. I have to use cygwin_dll_init
==============================
$ cat try.d
import std.stdio;
import std.string;
import core.sys.windows.windows;
extern(C)
{
alias int function(const (char)*, int, ...) open_t;
alias void function() init_t;
alias void function(const (char)*s) perror_t;
alias size_t function(int fs, void *buf, size_t count)
read_t;
open_t _my_open;
init_t init;
perror_t my_perror;
read_t my_read;
}
void main()
{
writefln("Open Library");
HMODULE mod = cast(HMODULE)
LoadLibrary("C:\\cygwin\\bin\\cygwin1.dll");
if (mod is null)
{
writefln("Failed load cygwin1.dll");
return;
}
writefln("Get Proc Init");
init = cast(init_t) GetProcAddress(mod,
"cygwin_dll_init");
if (init is null)
{
writefln("Failed open init symbol %s",
GetLastError());
return;
}
init();
writefln("Get Proc Open");
_my_open = cast(open_t) GetProcAddress(mod, "open");
if (_my_open is null)
{
writefln("Failed open open symbol %s",
GetLastError());
return;
}
writefln("Get Proc read");
my_read = cast(read_t) GetProcAddress(mod, "read");
if (my_read is null)
{
writefln("Failed open read symbol %s",
GetLastError());
return;
}
writefln("_open");
int res = (*_my_open)(toStringz("/proc/cpuinfo"), 0);
writefln("res=%s", res);
if (res < 0)
{
my_perror("Can't open file");
}
char[1024] buf;
my_read(res, buf.ptr, buf.length);
writefln("%s", buf);
}
========================================
$ ./try.exe
Open Library
Get Proc Init
Get Proc Open
Get Proc read
_open
res=0
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 76
model name : Intel(R) Pentium(R) CPU N3700 @ 1.60GHz
...
The problem of the method only errno variable which doesn't
content right error number.
More information about the Digitalmars-d
mailing list