www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Windows interface

reply Karl Bochert <Karl_member pathlink.com> writes:
I have been attempting to access the windows api from D, and there seem to be
api calls missing from std.windows.windows.

I have added to phobos:
export   HANDLE GetStdHandle(DWORD dev);
export   DWORD GetConsoleTitle(LPSTR buf, DWORD len);
export   BOOL AllocConsole();

but when I compile a program using them, I get from the linker:
winapp.obj(winapp)
Error 42: Symbol Undefined _GetConsoleTitle 8

Why does GetConsoleTitle() fail when the other 2 don't??
Jul 02 2006
next sibling parent Chris Nicholson-Sauls <ibisbasenji gmail.com> writes:
Karl Bochert wrote:
 I have been attempting to access the windows api from D, and there seem to be
 api calls missing from std.windows.windows.
 
 I have added to phobos:
 export   HANDLE GetStdHandle(DWORD dev);
 export   DWORD GetConsoleTitle(LPSTR buf, DWORD len);
 export   BOOL AllocConsole();
 
 but when I compile a program using them, I get from the linker:
 winapp.obj(winapp)
 Error 42: Symbol Undefined _GetConsoleTitle 8
 
 Why does GetConsoleTitle() fail when the other 2 don't??
 
 
Simple. Because there is no such function as GetConsoleTitle(). There are, however, both GetConsoleTitleA() for ANSI and GetConsoleTitleW() for Unicode. This is a common implementation detail throughout the Win32 API. In C/C++ there is a macro defined for each such function as the base name without the ANSI/Unicode suffix, as nothing more than a transparent wrap to one of the implementations. Something like: [code] void SomeFuncA(HANDLE, LPSTR); void SomeFuncW(HANDLE, LPWSTR); #ifdef _UNICODE_ #define SomeFunc(_A, _B) SomeFuncW(_A, _B) #else #define SomeFunc(_A, _B) SomeFuncA(_A, _B) #endif [/code] Simply change your additions to the following: Note that you don't neccessarily need the 'export' attribute -- so far as I am aware anyhow -- and also that you don't have to add these to Phobos. Instead, you may declare them in an import module in your own project. -- Chris Nicholson-Sauls
Jul 02 2006
prev sibling parent Don Clugston <dac nospam.com.au> writes:
Karl Bochert wrote:
 I have been attempting to access the windows api from D, and there seem to be
 api calls missing from std.windows.windows.
 
 I have added to phobos:
 export   HANDLE GetStdHandle(DWORD dev);
 export   DWORD GetConsoleTitle(LPSTR buf, DWORD len);
 export   BOOL AllocConsole();
 
 but when I compile a program using them, I get from the linker:
 winapp.obj(winapp)
 Error 42: Symbol Undefined _GetConsoleTitle 8
 
 Why does GetConsoleTitle() fail when the other 2 don't??
 
 
There are many windows APIs missing from Phobos. A relatively complete windows API is available from the Bindings project at www.dsource.org. (It's a work-in-progress, but already quite usable).
Jul 03 2006