FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

A little patch for WindowsAPI

 
Post new topic   Reply to topic     Forum Index -> Bindings
View previous topic :: View next topic  
Author Message
heromyth



Joined: 26 Nov 2006
Posts: 46

PostPosted: Wed Jul 25, 2007 3:42 am    Post subject: A little patch for WindowsAPI Reply with quote

Thank you for your great works. Here is a little fix for using smoothly.

Code:

Index: makefile
===================================================================
--- makefile   (revision 198)
+++ makefile   (working copy)
@@ -1,3 +1,5 @@
+# run mingw32-make -f Makefile
+
 DC := dmd.exe
 LIB := lib.exe
 
@@ -4,9 +6,11 @@
 DFLAGS := -inline -I.. -O -release -w
 DFLAGS += -version=Unicode -version=WindowsVista
 
+include sources
+
 ########################################
 
-SOURCES := $(wildcard *.d)
+SOURCES ?= $(wildcard *.d)
 OBJECTS := $(SOURCES:.d=.obj)
 
 ########################################
Index: sources
===================================================================
--- sources   (revision 0)
+++ sources   (revision 0)
@@ -0,0 +1,164 @@
+### Lists of source files, included by Makefiles
+
+## Bug:
+##     Can't be compiled files:   winsock.d
+#############################################
+
+
+SOURCES = \
+   accctrl.d \
+   aclapi.d \
+   aclui.d \
+   basetsd.d \
+   basetyps.d \
+   cderr.d \
+   cguid.d \
+   comcat.d \
+   commctrl.d \
+   commdlg.d \
+   core.d \
+   cpl.d \
+   cplext.d \
+   custcntl.d \
+   d3d9.d \
+   d3d9caps.d \
+   d3d9types.d \
+   dbt.d \
+   dde.d \
+   ddeml.d \
+   dhcpcsdk.d \
+   dlgs.d \
+   docobj.d \
+   dxerr8.d \
+   dxerr9.d \
+   errorrep.d \
+   exdisp.d \
+   exdispid.d \
+   httpext.d \
+   idispids.d \
+   imagehlp.d \
+   imm.d \
+   intshcut.d \
+   ipexport.d \
+   iphlpapi.d \
+   ipifcons.d \
+   iprtrmib.d \
+   iptypes.d \
+   isguids.d \
+   lm.d \
+   lmaccess.d \
+   lmalert.d \
+   lmapibuf.d \
+   lmat.d \
+   lmaudit.d \
+   lmbrowsr.d \
+   lmchdev.d \
+   lmconfig.d \
+   lmcons.d \
+   lmerr.d \
+   lmerrlog.d \
+   lmmsg.d \
+   lmremutl.d \
+   lmrepl.d \
+   lmserver.d \
+   lmshare.d \
+   lmsname.d \
+   lmstats.d \
+   lmsvc.d \
+   lmuse.d \
+   lmuseflg.d \
+   lmwksta.d \
+   lzexpand.d \
+   mapi.d \
+   mciavi.d \
+   mcx.d \
+   mgmtapi.d \
+   mmsystem.d \
+   msacm.d \
+   mshtml.d \
+   nb30.d \
+   nddeapi.d \
+   nspapi.d \
+   ntdef.d \
+   ntdll.d \
+   ntldap.d \
+   ntsecapi.d \
+   oaidl.d \
+   objbase.d \
+   objfwd.d \
+   objidl.d \
+   objsafe.d \
+   ocidl.d \
+   odbcinst.d \
+   ole.d \
+   ole2.d \
+   ole2ver.d \
+   oleacc.d \
+   oleauto.d \
+   olectl.d \
+   olectlid.d \
+   oledlg.d \
+   oleidl.d \
+   pbt.d \
+   powrprof.d \
+   prsht.d \
+   psapi.d \
+   rapi.d \
+   ras.d \
+   rasdlg.d \
+   raserror.d \
+   rassapi.d \
+   reason.d \
+   regstr.d \
+   richedit.d \
+   richole.d \
+   rpc.d \
+   rpcdce.d \
+   rpcdce2.d \
+   rpcdcep.d \
+   rpcndr.d \
+   rpcnsi.d \
+   rpcnsip.d \
+   rpcnterr.d \
+   schannel.d \
+   secext.d \
+   servprov.d \
+   setupapi.d \
+   shellapi.d \
+   shldisp.d \
+   shlguid.d \
+   shlobj.d \
+   shlwapi.d \
+   snmp.d \
+   sql.d \
+   sqlext.d \
+   sqltypes.d \
+   sqlucode.d \
+   subauth.d \
+   testall.d \
+   tmschema.d \
+   unknwn.d \
+   vfw.d \
+   w32api.d \
+   winbase.d \
+   winber.d \
+   wincon.d \
+   wincrypt.d \
+   windef.d \
+   windows.d \
+   winerror.d \
+   wingdi.d \
+   wininet.d \
+   winioctl.d \
+   winldap.d \
+   winnetwk.d \
+   winnls.d \
+   winnt.d \
+   winperf.d \
+   winreg.d \
+   winsock2.d \
+   winspool.d \
+   winsvc.d \
+   winuser.d \
+   winver.d \
+   wtypes.d
Index: wininet.d
===================================================================
--- wininet.d   (revision 198)
+++ wininet.d   (working copy)
@@ -266,10 +266,6 @@
    return !!(t & GOPHER_TYPE_FILE_MASK);
 }
 
-BOOL IS_GOPHER_FILE(DWORD t) {
-   return !!(t & GOPHER_TYPE_FILE_MASK);
-}
-
 BOOL IS_GOPHER_DIRECTORY(DWORD t) {
    return !!(t & GOPHER_TYPE_DIRECTORY);
 }

Back to top
View user's profile Send private message
heromyth



Joined: 26 Nov 2006
Posts: 46

PostPosted: Wed Jul 25, 2007 3:51 am    Post subject: Reply with quote

By the way, I post a sample for Win32API. It was come from DMD's winsamp.d. Hope all of you would like it Laughing

See here:

Code:


/*
 *   The win32.lib is placed in \dm\lib, and the sources of Win32API are in \dmd\src\phobos\win32
 *
 *   Compile with:
 *   dmd winsamp.d win32.lib gdi32.lib winsamp.def
 */

//import std.c.windows.windows;
import win32.windows;
import std.c.stdio;
import std.string;

const int IDC_BTNCLICK = 101;
const int IDC_BTNDONTCLICK = 102;

extern(Windows)
int WindowProc(HWND hWnd, uint uMsg, WPARAM wParam, LPARAM lParam)
{
   switch (uMsg)
   {
       case WM_COMMAND:
       {
      switch (LOWORD(wParam))
      {
          case IDC_BTNCLICK:
         if (HIWORD(wParam) == BN_CLICKED)
            MessageBoxA(hWnd, "Hello, world!", "Greeting",
               MB_OK | MB_ICONINFORMATION);
         break;
          case IDC_BTNDONTCLICK:
         if (HIWORD(wParam) == BN_CLICKED)
         {
             MessageBoxA(hWnd, "You've been warned...", "Prepare to GP fault",
                MB_OK | MB_ICONEXCLAMATION);
             *(cast(int*) null) = 666;
         }
         break;
      }
      break;
       }

       case WM_PAINT:
       {
      static char[] text = "D Does Windows";
      PAINTSTRUCT ps;
      HDC dc = BeginPaint(hWnd, &ps);      
      RECT r;
      GetClientRect(hWnd, &r);
      HFONT font = CreateFontA(80, 0, 0, 0, FW_EXTRABOLD, FALSE, FALSE,
         FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
         DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Arial");
      HGDIOBJ old = SelectObject(dc, cast(HGDIOBJ) font);
      SetTextAlign(dc, TA_CENTER | TA_BASELINE);
      TextOutA(dc, r.right / 2, r.bottom / 2, toStringz(text), text.length);
      SelectObject(dc, old);
      EndPaint(hWnd, &ps);
      break;
       }
       case WM_DESTROY:
      PostQuitMessage(0);
      break;

       default:
      break;
   }
   return DefWindowProcA(hWnd, uMsg, wParam, lParam);
}

int doit()
{
   HINSTANCE hInst = GetModuleHandleA(null);
   WNDCLASS wc;
   wc.lpszClassName = "DWndClass";
   wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
   wc.lpfnWndProc = &WindowProc;
   wc.hInstance = hInst;
   wc.hIcon = LoadIconA(cast(HINSTANCE) null, IDI_APPLICATION);
   wc.hCursor = LoadCursorA(cast(HINSTANCE) null, IDC_CROSS);
   wc.hbrBackground = cast(HBRUSH) (COLOR_WINDOW + 1);
   wc.lpszMenuName = null;
   wc.cbClsExtra = wc.cbWndExtra = 0;
   RegisterClassA(&wc);
   
   HWND hWnd, btnClick, btnDontClick;
   hWnd = CreateWindowA("DWndClass", "Just a window", WS_THICKFRAME |
      WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_SYSMENU | WS_VISIBLE,
      CW_USEDEFAULT, CW_USEDEFAULT, 400, 300, HWND_DESKTOP,
      cast(HMENU) null, hInst, null);
   assert(hWnd);
   
   btnClick = CreateWindowA("BUTTON", "Click Me", WS_CHILD | WS_VISIBLE,
      0, 0, 100, 25, hWnd, cast(HMENU) IDC_BTNCLICK, hInst, null);

   btnDontClick = CreateWindowA("BUTTON", "DON'T CLICK!", WS_CHILD | WS_VISIBLE,
      110, 0, 100, 25, hWnd, cast(HMENU) IDC_BTNDONTCLICK, hInst, null);

   MSG msg;
   while (GetMessageA(&msg, cast(HWND) null, 0, 0))
   {
      TranslateMessage(&msg);
      DispatchMessageA(&msg);
   }
   
   return 1;
}

/**********************************************************/

/* Note the similarity of this code to the console D startup
 * code in \dmd\src\phobos\dmain2.d
 * You'll also need a .def file with at least the following in it:
 *   EXETYPE NT
 *   SUBSYSTEM WINDOWS
 */

extern (C) void gc_init();
extern (C) void gc_term();
extern (C) void _minit();
extern (C) void _moduleCtor();
extern (C) void _moduleUnitTests();

extern (Windows)
int WinMain(HINSTANCE hInstance,
   HINSTANCE hPrevInstance,
   LPSTR lpCmdLine,
   int nCmdShow)
{
    int result;

    gc_init();         // initialize garbage collector
    _minit();         // initialize module constructor table

    try
    {
   _moduleCtor();      // call module constructors
   _moduleUnitTests();   // run unit tests (optional)

   result = doit();   // insert user code here
    }

    catch (Object o)      // catch any uncaught exceptions
    {
   MessageBoxA(null, cast(char *)o.toString(), "Error",
          MB_OK | MB_ICONEXCLAMATION);
   result = 0;      // failed
    }

    gc_term();         // run finalizers; terminate garbage collector
    return result;
}

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Bindings All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group