www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Can't get winapi working

reply dozksaw <dozksaw ee2.pl> writes:
Hi. I was trying all day to get this working, but i give up and 
post it here.

module tryingwinapi;

import core.runtime;
import std.utf;

auto toUTF16z(S)(S s)
{
     return toUTFz!(const(wchar)*)(s);
}

import win32.windef;
import win32.winuser;

extern (Windows)
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR 
lpCmdLine, int iCmdShow)
{
     int result;
     void exceptionHandler(Throwable e) { throw e; }

     try
     {
         Runtime.initialize(&exceptionHandler);
         result = myWinMain(hInstance, hPrevInstance, lpCmdLine, 
iCmdShow);
         Runtime.terminate(&exceptionHandler);
     }
     catch (Throwable o)
     {
         MessageBox(null, o.toString().toUTF16z, "Error", MB_OK | 
MB_ICONEXCLAMATION);
         result = 0;
     }

     return result;
}

int myWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR 
lpCmdLine, int iCmdShow)
{
     MessageBox(NULL, "Hello, Windows!", "Your Application", 0);
     return 0;
}

I have found that code here 
https://github.com/AndrejMitrovic/DWinProgramming/blob/master/Samples/Chap01/HelloMsg/HelloMsg.d
I have copied the win32 directory from his github.
Thats how my directory looks:
ls
win32  winapi.d
Getting this error:
dmd winapi.d
win32/winnt.d(2130): Error: undefined identifier 'CONTEXT', did 
you mean alias 'PCONTEXT'?
win32/winnt.d(2130): Error: undefined identifier 'CONTEXT', did 
you mean alias 'PCONTEXT'?
win32/winbase.d(2004): Error: undefined identifier 'CONTEXT', did 
you mean alias 'PCONTEXT'?

I was trying another code what i found on the web:
module tryingwinapi;

import core.runtime;
import core.sys.windows.windows;

extern(Windows)  int WinMain( HINSTANCE hInstance, HINSTANCE 
hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
     MessageBox( NULL, "text", "title", MB_OKCANCEL);
     return 0;
}

This returns me:
dmd winapi.d
winapi.d(6): Error: undefined identifier 'HINSTANCE'
winapi.d(6): Error: undefined identifier 'HINSTANCE'
winapi.d(6): Error: undefined identifier 'LPSTR'


What is the correct code to show the MessageBox in windows?
Nov 01 2015
parent Vladimir Panteleev <thecybershadow.lists gmail.com> writes:
On Sunday, 1 November 2015 at 17:52:08 UTC, dozksaw wrote:
 I have copied the win32 directory from his github.
Try the official repository: https://github.com/smjgordon/bindings/tree/master/win32 These headers will also be available as core.sys.windows.* starting with D 2.070.
Nov 01 2015