www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19372] New: Request for more "D style" win32api

https://issues.dlang.org/show_bug.cgi?id=19372

          Issue ID: 19372
           Summary: Request for more "D style" win32api
           Product: D
           Version: D2
          Hardware: All
               URL: http://dlang.org/
                OS: Windows
            Status: NEW
          Severity: enhancement
          Priority: P3
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: kohei-coco jcom.home.ne.jp

I'm developing an application for Windows platform using Phobos library
"core.sys.windows.windows".
Then I feel that the current libraries are not "D style".
Firstly, the official sample code [https://wiki.dlang.org/D_for_Win32] is shown
below.
---
 1| import core.runtime;
 2| import core.sys.windows.windows;
 3| import std.string;
 4|
 5| extern(Windows)
 6| int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
int nCmdShow){
 7|   int result;
 8|
 9|   try{
10|     Runtime.initialize();
11|     result= myWinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
12|     Runtime.terminate();
13|   }
14|   catch(Throwable e){
15|     MessageBoxA(null, e.toString().toStringz(), null, MB_ICONEXCLAMATION);
16|     result= 0;     // failed
17|   }
18|
19|   return result;
20| }
21|
22| int myWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR
lpCmdLine, int nCmdShow){
23|   // ... insert user code here ...
24|   return 0;
25| }
---

Considering the above, I have two opinions.
(I) Functions name should be camelCased[https://dlang.org/dstyle.html].
I think almost all win32API functions are named with starts capital letter at
first
For example, at line 6, "WinMain" should be "winMain".
Likewise, at line 15, "MessageBoxA" to "messageBoxA".

(II) Usage of enums with classification
At line 15, the last argument of the function is a manifest constant
"MB_ICONEXCLAMATION".
This value is defined at line 851 in "core.sys.windows.winuser" as follows.
---
enum{
  MB_OK= 0,
  MB_OKCANCEL,
  ...
  MB_ICONEXCLAMATION= 0x00000030,
  ...
}
---
I think these manifest constants are defined with a clasification as follows.
---
enum MessageBoxStyle: uint{
  Ok= 0u,
  OkCancel,
  ...
  IconExclamation= 0x0000_0030u,
  ...
}
---
If you agree to my opinions, please solve these issues.

--
Nov 06 2018