www.digitalmars.com         C & C++   DMDScript  

D - how to call a couple of functions...

reply "Carlos" <carlos8294 msn.com> writes:
Maybe it's too simple or I've lost practice (lack of spare time), but what
should I add to my program to use SetConsoleTextAttribute() and
GetStdHandle()? Thanks in advance.
Jun 11 2002
parent reply "Sean L. Palmer" <seanpalmer earthlink.net> writes:
Go to Pavel's DedicateD site and get his Windows.d api wrapper.  It's much
more complete than the one that comes with the D compiler.

Sean

"Carlos" <carlos8294 msn.com> wrote in message
news:ae632a$l6v$1 digitaldaemon.com...
 Maybe it's too simple or I've lost practice (lack of spare time), but what
 should I add to my program to use SetConsoleTextAttribute() and
 GetStdHandle()? Thanks in advance.

Jun 11 2002
next sibling parent reply "Pavel Minayev" <evilone omen.ru> writes:
"Sean L. Palmer" <seanpalmer earthlink.net> wrote in message
news:ae6pkd$1bem$1 digitaldaemon.com...

 Go to Pavel's DedicateD site and get his Windows.d api wrapper.  It's much
 more complete than the one that comes with the D compiler.

And also much more buggy... but that's another story. In general, unless you use MANY API functions, I highly recommend that you write prototypes for them yourself, and then submit whatever you get to Walter for inclusion into his windows.d. Not only your code will be cleaner, but we will also get a hand-crafted WinAPI import file at some point in the future.
Jun 12 2002
parent reply "Sean L. Palmer" <seanpalmer earthlink.net> writes:
I say just take yours (minus the parts that conflict with Walter's) and just
fix the bugs that turn up.

Otherwise Walter will never get around to it.  That's a LOT of headers to go
through and fix up and convert.

Sean

"Pavel Minayev" <evilone omen.ru> wrote in message
news:ae710s$1k2e$1 digitaldaemon.com...
 "Sean L. Palmer" <seanpalmer earthlink.net> wrote in message
 news:ae6pkd$1bem$1 digitaldaemon.com...

 Go to Pavel's DedicateD site and get his Windows.d api wrapper.  It's


 more complete than the one that comes with the D compiler.

And also much more buggy... but that's another story. In general, unless you use MANY API functions, I highly recommend that you write prototypes for them yourself, and then submit whatever you get to Walter for inclusion into his windows.d. Not only your code will be cleaner, but we will also get a hand-crafted WinAPI import file at some point in the future.

Jun 12 2002
parent "Pavel Minayev" <evilone omen.ru> writes:
"Sean L. Palmer" <seanpalmer earthlink.net> wrote in message
news:ae75gv$1pek$1 digitaldaemon.com...

 I say just take yours (minus the parts that conflict with Walter's) and

 fix the bugs that turn up.

 Otherwise Walter will never get around to it.  That's a LOT of headers to

 through and fix up and convert.

There are a few problems that need to be solved first. The biggest one is that Phobos won't compile with my windows.d, due to some type differences. For example, my version assumes HANDLE it an uint (because it originates from Pascal unit), while Walter correctly defines it as void*. As the result, you cannot use "null" whenever a null handle is required in my version, but have to employ 0 (or the NULL constant), while Walter's version requires null...
Jun 12 2002
prev sibling parent reply "Carlos" <carlos8294 msn.com> writes:
"Sean L. Palmer" <seanpalmer earthlink.net> escribió en el mensaje
news:ae6pkd$1bem$1 digitaldaemon.com...
 Go to Pavel's DedicateD site and get his Windows.d api wrapper.  It's much
 more complete than the one that comes with the D compiler.

 Sean

because i can't get them to work...
Jun 17 2002
parent reply "Carlos" <carlos8294 msn.com> writes:
"Carlos" <carlos8294 msn.com> escribió en el mensaje
news:aelghu$act$2 digitaldaemon.com...
 "Sean L. Palmer" <seanpalmer earthlink.net> escribió en el mensaje
 news:ae6pkd$1bem$1 digitaldaemon.com...
 Go to Pavel's DedicateD site and get his Windows.d api wrapper.  It's


 more complete than the one that comes with the D compiler.

 Sean

because i can't get them to work...

ok, sorry. my mistake. they do work. this is what happened: i made a test program and named it color. so when i ran it, nothing happened. obviously! win xp (don't know if 2000 or nt have) has a color command itself!
Jun 17 2002
next sibling parent reply "Carlos" <carlos8294 msn.com> writes:
 Go to Pavel's DedicateD site and get his Windows.d api wrapper.  It's



I'm using Pavel's file, but I get these errors. What's wrong with this code? void gotoxy(int x, int y) { COORD c; c.X = x - 1; c.Y = y - 1; SetConsoleCursorPosition (GetStdHandle(STD_OUTPUT_HANDLE), c); } by itself, it generates an error (Error 42: Symbol Undefined _SetConsoleCursorPosition 12). what does the mean? it's not the line number... Almost the same happens here: (Error 42: Symbol Undefined _FillConsoleOutputCharacterW 24) void clrscr() { COORD coord; DWORD written; CONSOLE_SCREEN_BUFFER_INFO info; coord.X = 0; coord.Y = 0; GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info); FillConsoleOutputCharacterW (GetStdHandle(STD_OUTPUT_HANDLE), ' ', info.dwSize.X * info.dwSize.Y, coord, &written); gotoxy (1, 1); } And while this works fine... int wherex() { CONSOLE_SCREEN_BUFFER_INFO info; GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info); return info.dwCursorPosition.X; } this doesn't... int wherey() { CONSOLE_SCREEN_BUFFER_INFO info; GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info); return info.dwCursorPosition.Y - 2; } Why?
Jun 17 2002
next sibling parent reply "Sean L. Palmer" <seanpalmer earthlink.net> writes:
You would also have to link with the Windows DLL which implements
GetConsoleScreenBufferInfo and FillConsoleOutputCharacterW.  I believe
that's kernel32.dll... so you need an import library kernel32.lib.  Luckily
it's distributed with D (or should be... on Pavel's site same place as the
windows.d if not).

Some kind of command like:

c:\dmd\bin\dmd.exe myapp.d kernel32.lib

It really doesn't get much simpler than that.  Maybe have modules (in
Windows version of D at least) give some signal to link.exe that it should
link in some .LIB file or .OBJ file or multiple ones during link phase.  I
would *love* the ability to embed that information in the language somehow
(some kind of "link" keyword might even be nice).  Isn't linking universal?
You always have to link.  So we can embed the concept of linkage into our
programs as a language construct.  If you don't do it there you end up
needing some kind of external file for the same info anyway (.makefile)
which is not central to the point where integration is known (in the .OBJ
files that the linker is manipulating is embedded commands to it passed thru
by the compiler from the source code.) Maybe set it up so you can drag the
pretty *.D files' icons onto the pretty DMD.EXE icon to compile and run it.
Something your grandmother could accomplish.

Then newbie questions could easily be avoided by having windows.d
automatically cause linkage with kernel32.lib (and gdi32.lib, and
user32.lib, and oleaut64e.lib these days).  Not that it's a problem
really... it would be nice to see more new faces around here.  ;)

D would be pretty easy to learn, probably about as hard as pascal to master.
I think it would make a really good first language if only it were more
seasoned.  Language is not even beta yet.  And by the time of D 2.0 it might
be a more developed language, a bit harder to master but a much better
day-to-day tool.  I don't care what is elegant; a compiler is a tool for the
programmer and serves only to make his job (and life!) easier if that's at
all possible.  Without having to remember all kinds of little trivia about
what header links with what dll.

Walter:  what is the release timetable for D 1.0?  When is beta and release
scheduled?   Maybe so we can start debating D 2.0   ;)  Seriously this seems
to be gelling... a few bugs and maybe some more optimizations (don't want to
make D look bad right off the bat by being the "slow" language) but
otherwise the compiler seems pretty solid and getting quite to the point of
stopping adding features to D 1.0.  Unless anyone knows of anything
seriously lacking in the language at present which needs immediate
addressing.

Sean

"Carlos" <carlos8294 msn.com> wrote in message
news:aelp0m$imq$1 digitaldaemon.com...
 Go to Pavel's DedicateD site and get his Windows.d api wrapper.






I'm using Pavel's file, but I get these errors. What's wrong with this

 void gotoxy(int x, int y) {
     COORD c;
     c.X = x - 1;
     c.Y = y - 1;
     SetConsoleCursorPosition (GetStdHandle(STD_OUTPUT_HANDLE), c);
 }

 by itself, it generates an error (Error 42: Symbol Undefined
 _SetConsoleCursorPosition 12). what does the   mean? it's not the line
 number...

 Almost the same happens here: (Error 42: Symbol Undefined
 _FillConsoleOutputCharacterW 24)

 void clrscr() {
     COORD coord;
     DWORD written;
     CONSOLE_SCREEN_BUFFER_INFO info;

     coord.X = 0;
     coord.Y = 0;
     GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);
     FillConsoleOutputCharacterW (GetStdHandle(STD_OUTPUT_HANDLE), ' ',
         info.dwSize.X * info.dwSize.Y, coord, &written);
     gotoxy (1, 1);
 }

 And while this works fine...

 int wherex() {
     CONSOLE_SCREEN_BUFFER_INFO info;
     GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);
     return info.dwCursorPosition.X;
 }

 this doesn't...

 int wherey() {
     CONSOLE_SCREEN_BUFFER_INFO info;
     GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);
     return info.dwCursorPosition.Y - 2;
 }

 Why?

Jun 17 2002
next sibling parent Pavel Minayev <evilone omen.ru> writes:
On Mon, 17 Jun 2002 22:57:22 -0700 "Sean L. Palmer" <seanpalmer earthlink.net> 
wrote:

 stopping adding features to D 1.0.  Unless anyone knows of anything
 seriously lacking in the language at present which needs immediate
 addressing.

Well, things that are in the specs but missing from the compiler are property gettors/settors (but I guess we'll see them soon), and inheritance for in & out blocks.
Jun 18 2002
prev sibling next sibling parent reply "Walter" <walter digitalmars.com> writes:
"Sean L. Palmer" <seanpalmer earthlink.net> wrote in message
news:aemhj8$1a3d$1 digitaldaemon.com...
 Walter:  what is the release timetable for D 1.0?  When is beta and

 scheduled?   Maybe so we can start debating D 2.0   ;)  Seriously this

 to be gelling... a few bugs and maybe some more optimizations (don't want

 make D look bad right off the bat by being the "slow" language) but
 otherwise the compiler seems pretty solid and getting quite to the point

 stopping adding features to D 1.0.  Unless anyone knows of anything
 seriously lacking in the language at present which needs immediate
 addressing.

At the moment I think it just needs another go-round to fix the reported bugs, do the property gettor/settor, and it should be beta-able.
Jun 18 2002
parent "Sean L. Palmer" <seanpalmer earthlink.net> writes:
Weeee!

"Walter" <walter digitalmars.com> wrote in message
news:aenrvg$2mqr$2 digitaldaemon.com...
 At the moment I think it just needs another go-round to fix the reported
 bugs, do the property gettor/settor, and it should be beta-able.

Jun 18 2002
prev sibling parent "Carlos" <carlos8294 msn.com> writes:
"Sean L. Palmer" <seanpalmer earthlink.net> escribió en el mensaje
news:aemhj8$1a3d$1 digitaldaemon.com...
 You would also have to link with the Windows DLL which implements
 GetConsoleScreenBufferInfo and FillConsoleOutputCharacterW.  I believe
 that's kernel32.dll... so you need an import library kernel32.lib.

 it's distributed with D (or should be... on Pavel's site same place as the
 windows.d if not).

 Some kind of command like:

 c:\dmd\bin\dmd.exe myapp.d kernel32.lib

.lib files (since you said "I believe that's kernel32.dll"), but nothing happened. I even tried this: dmd myapp *.lib But it was the same. Another idea?
Jun 18 2002
prev sibling parent reply "Juan Carlos Arevalo Baeza" <jcab roningames.com> writes:
"Carlos" <carlos8294 msn.com> wrote in message
news:aelp0m$imq$1 digitaldaemon.com...

 What's wrong with this code?

 void gotoxy(int x, int y) {
     COORD c;
     c.X = x - 1;
     c.Y = y - 1;
     SetConsoleCursorPosition (GetStdHandle(STD_OUTPUT_HANDLE), c);
 }

 by itself, it generates an error (Error 42: Symbol Undefined
 _SetConsoleCursorPosition 12). what does the   mean? it's not the line
 number...

The separates the name from the number of bytes of stack used. It's generally used for functions that clean up the stack themselves (was that pascal calling conventions?), I believe. All the windows API functions use that convention. So, the compiler thinks that SetConsoleCursorPosition() accepts 12 bytes, or three dword parameters. In fact, that API function accepts 8 bytes (2 dwords). COORD contains two SHORT values, which are 16 bits each. So, I believe it's the wrapper that's wrong. In fact, it is. I just went to pavel's site, and downloaded it, and in line 63: alias int SHORT; this should be... whichever type is a 16-bit signed integer in D. It does have one, I hope... Salutaciones, JCAB
Jun 18 2002
parent reply "Carlos" <carlos8294 msn.com> writes:
    In fact, it is. I just went to pavel's site, and downloaded it, and in
 line 63:

 alias int SHORT;

    this should be... whichever type is a 16-bit signed integer in D. It

 have one, I hope...

 Salutaciones,
                          JCAB

alias short SHORT; ?
Jun 18 2002
next sibling parent reply "Carlos" <carlos8294 msn.com> writes:
"Carlos" <carlos8294 msn.com> escribió en el mensaje
news:aeo6ie$hq$1 digitaldaemon.com...
    In fact, it is. I just went to pavel's site, and downloaded it, and


 line 63:

 alias int SHORT;

    this should be... whichever type is a 16-bit signed integer in D. It

 have one, I hope...

 Salutaciones,
                          JCAB

alias short SHORT; ?

Jun 18 2002
parent Pavel Minayev <evilone omen.ru> writes:
On Tue, 18 Jun 2002 16:00:47 -0500 "Carlos" <carlos8294 msn.com> wrote:

 Thank you, Juan Carlos! It worked! Pavel, there's a mistake in windows.d

Yes, I see now. I'll correct this. Anyhow, I still _highly_ recommend to extract all required structure and function prototypes from windows.d and insert them into your module, and then make sure it will compile with Walter's windows.d. This is exactly what I'm doing with my modules right now, and I've already got rid of dependencies of socket.d and winsock.d.
Jun 19 2002
prev sibling parent reply "Carlos" <carlos8294 msn.com> writes:
"Carlos" <carlos8294 msn.com> escribió en el mensaje
news:aeo6ie$hq$1 digitaldaemon.com...
    In fact, it is. I just went to pavel's site, and downloaded it, and


 line 63:

 alias int SHORT;

    this should be... whichever type is a 16-bit signed integer in D. It

 have one, I hope...

 Salutaciones,
                          JCAB

alias short SHORT; ?

Jun 18 2002
parent "Juan Carlos Arevalo Baeza" <jcab roningames.com> writes:
"Carlos" <carlos8294 msn.com> wrote in message
news:aeo6q5$108$1 digitaldaemon.com...

 alias short SHORT;

 ?


:) Cool. Salutaciones, JCAB
Jun 18 2002
prev sibling next sibling parent "Sean L. Palmer" <seanpalmer earthlink.net> writes:
Now that's funny.  ;)

Sean

"Carlos" <carlos8294 msn.com> wrote in message
news:aeljej$dh8$1 digitaldaemon.com...
 "Carlos" <carlos8294 msn.com> escribió en el mensaje
 news:aelghu$act$2 digitaldaemon.com...
 "Sean L. Palmer" <seanpalmer earthlink.net> escribió en el mensaje
 news:ae6pkd$1bem$1 digitaldaemon.com...
 Go to Pavel's DedicateD site and get his Windows.d api wrapper.  It's


 more complete than the one that comes with the D compiler.

 Sean

because i can't get them to work...

ok, sorry. my mistake. they do work. this is what happened: i made a test program and named it color. so when i ran it, nothing happened. obviously! win xp (don't know if 2000 or nt have) has a color command itself!

Jun 17 2002
prev sibling parent "Matthew Wilson" <matthew thedjournal.com> writes:
they do

"Carlos" <carlos8294 msn.com> wrote in message
news:aeljej$dh8$1 digitaldaemon.com...
 "Carlos" <carlos8294 msn.com> escribió en el mensaje
 news:aelghu$act$2 digitaldaemon.com...
 "Sean L. Palmer" <seanpalmer earthlink.net> escribió en el mensaje
 news:ae6pkd$1bem$1 digitaldaemon.com...
 Go to Pavel's DedicateD site and get his Windows.d api wrapper.  It's


 more complete than the one that comes with the D compiler.

 Sean

because i can't get them to work...

ok, sorry. my mistake. they do work. this is what happened: i made a test program and named it color. so when i ran it, nothing happened. obviously! win xp (don't know if 2000 or nt have) has a color command itself!

Jun 17 2002