Suggestion to use common Win32 headers

bobef bobef at abv-nospam.bg
Wed Mar 5 13:05:54 PST 2008


Trevor Parscal Wrote:

> As the person who contributed Tango's minimal windows header, and also has authored a new even more restrictive header for my own project UniD, I feel I may be a good person to answer this question.
> 

I didn't intend to insult you by saying 'minimal'. In this context 'minimal' means only the types and constants basically, which are very useful, of course. The problem is

1) These are not common with Phobos. I.e. Phobos may provide less (or more) win32 types and constants.
2) Other libraries are not using these (probably because of 1)
3) This causes conflicts
4) There are no functions, only types and constants

> "Windows headers" can mean just windows.h or poitentially hundreds of files which for the majority of users are not needed. Even with automatic conversion software (h2d) it is a tedious process to get bug-free D modules from C header files.
> 
> So it's often been a question of scope; how many headers should we consider "common"?
> 

I am not saying 'common'. I am saying all (or most of) win32 headers. There is no need for conversations or anything. The headers are already there - http://dsource.org/projects/bindings/browser/trunk/win32
So what needs to be done, IMHO, is for Phobos and Tango to adopt these. So one could just write import win32.windows;

The only problem I see with this is that these headers are massive and not needed by linux users. I don't know this could be solved. But I see a bigger problem when I have to manually define each win32 function that I am using even though there are the appropriate headers available. And yet they remain virtually useless because they conflict with at least one more library.

To outline the problem once more- imagine this scenario (which I believe is not uncommon for win32 apps):

You need to write a Win32 GUI app that does more than just windows.
So, naturally, you choose to use DFL or DWT (I don't know if wxD or gtkD suffers from these problems) to do your windows.
The first problem arises when these (DFL or DWT) conflict with Tango/Phobos win32 declarations. This is somehow solvable but still very annoying.
Now if you need to do some not-so-common task and need some win32 functionality what do you do?
1) copy function declarations from MSDN or existing D headers, which is annoying and potentially the cause of conflicts. For example - the function you have just specified needs a HANDLE from, say, DFL. You write something like extern(Windows) VOID SomeWin32Function(HANDLE); And here is the conflict. I include tango.sys.win32.Types in my program, not the internal DFL stuff, but DFL returns HANDLE that is defined in it's internal files, not in tango....Types. You could probably include dfl.internal.winapi or something like that, instead of tango.Types, but this is ugly and not applicable to libraries that needs to be distributed.
2) try to use some existing headers like the ones in the bindings projects. But they become absolutely unusable because they conflict with both Tango and DFL. Why with both? Because if you are writing a library you can't make it depend (in most cases) on DFL's internal winapi definition, so you use tango.sys.win32.Types where you need win32 types and DFL uses its internal stuff and you get 3 conflicts. So you are stuck with point 1
3) correct me if I am wrong



More information about the Digitalmars-d mailing list