Programming with windows api (windows.h)

monarch_dodra monarchdodra at gmail.com
Mon Dec 17 08:21:08 PST 2012


I'm a bit confused about how to interface with windows.h.

All I'm trying to do is retrieve some text from my clipboard to 
print it.

So far, I have this:

//----
import std.stdio;

import core.sys.windows.windows;

extern (Windows)
{
   HWND   GetClipboardOwner();
   BOOL   OpenClipboard(HWND hWndNewOwner);
   HANDLE GetClipboardData(UINT uFormat);
}

void main()
{
   HWND hWnd = GetClipboardOwner();

   if ( hWnd == null ) {stderr.writeln("Problem."); return;}
   if ( OpenClipboard(hWnd) == 0 ) {stderr.writeln("Problem 2."); 
return;}

   hWnd = cast(HWND)GetClipboardData(CF_TEXT);
}
//----

This works, but as you can see, I have to declare as "extern 
(Windows)" all the functions myself. Not pretty, but works I 
guess. I'm hitting a wall at "CF_TEXT" though: That's an enum.

Anyways...

Am I doing it wrong, or are is the amount of ported windows 
interface currently limited...

Kinda lost here (The fact that I'm also new to windows 
programming doesn't help...) :)


More information about the Digitalmars-d-learn mailing list