Can't call GetWindowTextW - Error:undefined identifier

John Chapman via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jun 17 13:50:24 PDT 2015


On Wednesday, 17 June 2015 at 20:40:02 UTC, Dan wrote:
> I'm new to Dlang and I have no Idea whats wrong with this code!
>
> wchar[260] buffer;
> HWND hWindow = GetForegroundWindow();
> GetWindowTextW(hWindow, buffer, sizeof(title)); <-- Problem here

The compiler is complaining it can't find an identifier named 
GetWindowTextW, so you'll have to declare it yourself.

Try this:

   extern(Windows)
   int GetWindowTextW(HWND hWnd, LPWSTR lpString, int nMaxCount);

And call it like so:

   wchar[MAX_PATH] buffer;
   int length = GetWindowTextW(GetForegroundWindow(), buffer.ptr, 
buffer.length);


More information about the Digitalmars-d-learn mailing list