digitalmars.D - Windows API Translation
- Andrew Wiley (19/19) Feb 07 2011 I'm trying to use the Windows file change notification API from D, and
- Lars T. Kyllingstad (16/39) Feb 07 2011 I think you have to use either the FindFirstChangeNotificationW function...
- Vladimir Panteleev (9/28) Feb 07 2011 Are you linking with the appropriate import library?
- Lars T. Kyllingstad (5/37) Feb 07 2011 Wow, I didn't know this existed. I wonder if these bindings would be
- Vladimir Panteleev (8/11) Feb 08 2011 That would be great. I had to use Tango, Phobos (via Tangobos), these
- novice2 (1/4) Feb 08 2011 one bad (imho) thing - functions parameters names removed :( just types ...
- Don (3/8) Feb 08 2011 That's because the code is derived from MingW, not from the Microsoft
- Trass3r (1/2) Feb 08 2011 They definitely need to be merged.
- Stewart Gordon (4/6) Feb 08 2011 Merged? The whole point of the bindings project is that it will one day...
- Matthias Pleh (7/16) Feb 08 2011 VisualD has some code for automated winapi-conversion:
- Rainer Schuetze (21/45) Feb 09 2011 Yes, building Visual D uses a tool that machine translates about 40
- Don (3/58) Feb 09 2011 I believe he does. But it was a newsgroup post many years ago, I don't
-
Stewart Gordon
(9/11)
Feb 10 2011
- Rainer Schuetze (12/27) Feb 12 2011 I guess it can be tweaked without too much effort to work with the MinGW...
- Trass3r (1/6) Feb 08 2011 FindFirstChangeNotification is - like any other Windows function that re...
- Kagamin (2/9) Feb 08 2011 D string encoding is not configurable. What configuration are you talkin...
- dennis luehring (34/43) Feb 08 2011 he talks about stuff like that (from winbase.h - vs2010)
- Andrew Wiley (8/17) Feb 08 2011 ceives a string - just an alias that points to a version with suffix W o...
- dennis luehring (6/15) Feb 08 2011 or these typical win-api phobos constructs
- Walter Bright (27/50) Feb 08 2011 Here is the declaration from \dm\include\win32\winbase.h:
I'm trying to use the Windows file change notification API from D, and I'm having trouble translating Microsoft's macro-laden signatures into D. I thought I had it figured out, but optlink says otherwise: The original function is this: HANDLE WINAPI FindFirstChangeNotification( __in=A0=A0LPCTSTR lpPathName, __in=A0=A0BOOL bWatchSubtree, __in=A0=A0DWORD dwNotifyFilter ); I translated it into: extern(Windows) { uint FindFirstChangeNotification( const(char)* lpPathName, bool bWatchSubtree, uint dwNotifyFilter ); } Optlink is giving me undefined symbol errors, but I can't seem to figure out what I have wrong. Any help would be appreciated.
Feb 07 2011
On Tue, 08 Feb 2011 01:10:02 -0600, Andrew Wiley wrote:I'm trying to use the Windows file change notification API from D, and I'm having trouble translating Microsoft's macro-laden signatures into D. I thought I had it figured out, but optlink says otherwise: The original function is this: HANDLE WINAPI FindFirstChangeNotification( __in  LPCTSTR lpPathName, __in  BOOL bWatchSubtree, __in  DWORD dwNotifyFilter ); I translated it into: extern(Windows) { uint FindFirstChangeNotification( const(char)* lpPathName, bool bWatchSubtree, uint dwNotifyFilter ); } Optlink is giving me undefined symbol errors, but I can't seem to figure out what I have wrong. Any help would be appreciated.I think you have to use either the FindFirstChangeNotificationW function (Unicode) or FindFirstChangeNotificationA function (ANSI) -- probably the former. Also, if you import core.sys.windows.windows, you can use the Windows API types directly: import core.sys.windows.windows; extern(Windows) HANDLE FindFirstChangeNotification( LPCWSTR lpPathName, BOOL bWatchSubtree, DWORD dwNotifyFilter ); Note that I replaced LPCTSTR with LPCWSTR, which is a UTF-16 string, i.e. an alias for const(wchar)* and not const(char)*. This means that you have to use the std.utf.toUTF16z() function to convert normal strings before passing them to the function. -Lars
Feb 07 2011
On Tue, 08 Feb 2011 09:10:02 +0200, Andrew Wiley <debio264 gmail.com> wrote:I'm trying to use the Windows file change notification API from D, and I'm having trouble translating Microsoft's macro-laden signatures into D. I thought I had it figured out, but optlink says otherwise: The original function is this: HANDLE WINAPI FindFirstChangeNotification( __in LPCTSTR lpPathName, __in BOOL bWatchSubtree, __in DWORD dwNotifyFilter ); I translated it into: extern(Windows) { uint FindFirstChangeNotification( const(char)* lpPathName, bool bWatchSubtree, uint dwNotifyFilter ); } Optlink is giving me undefined symbol errors, but I can't seem to figure out what I have wrong. Any help would be appreciated.Are you linking with the appropriate import library? You may also want to have a look at the Win32 bindings project (which also has this function among many others): http://dsource.org/projects/bindings/wiki/WindowsApi -- Best regards, Vladimir mailto:vladimir thecybershadow.net
Feb 07 2011
On Tue, 08 Feb 2011 09:36:54 +0200, Vladimir Panteleev wrote:On Tue, 08 Feb 2011 09:10:02 +0200, Andrew Wiley <debio264 gmail.com> wrote:Wow, I didn't know this existed. I wonder if these bindings would be suitable for inclusion in the core.sys.windows package? Currently, core.sys.windows.windows only contains a small subset of the Windows API. -LarsI'm trying to use the Windows file change notification API from D, and I'm having trouble translating Microsoft's macro-laden signatures into D. I thought I had it figured out, but optlink says otherwise: The original function is this: HANDLE WINAPI FindFirstChangeNotification( __in LPCTSTR lpPathName, __in BOOL bWatchSubtree, __in DWORD dwNotifyFilter ); I translated it into: extern(Windows) { uint FindFirstChangeNotification( const(char)* lpPathName, bool bWatchSubtree, uint dwNotifyFilter ); } Optlink is giving me undefined symbol errors, but I can't seem to figure out what I have wrong. Any help would be appreciated.Are you linking with the appropriate import library? You may also want to have a look at the Win32 bindings project (which also has this function among many others): http://dsource.org/projects/bindings/wiki/WindowsApi
Feb 07 2011
On Tue, 08 Feb 2011 09:52:24 +0200, Lars T. Kyllingstad <public kyllingen.nospamnet> wrote:Wow, I didn't know this existed. I wonder if these bindings would be suitable for inclusion in the core.sys.windows package? Currently, core.sys.windows.windows only contains a small subset of the Windows API.That would be great. I had to use Tango, Phobos (via Tangobos), these bindings and dwin in the same project once, and three of those four had their own definitions of the basic Win32 types. Not fun. -- Best regards, Vladimir mailto:vladimir thecybershadow.net
Feb 08 2011
one bad (imho) thing - functions parameters names removed :( just types remains. it is make self-documentation or fast-look-to-remember harder :(Wow, I didn't know this existed. I wonder if these bindings would be suitable for inclusion in the core.sys.windows package? Currently, core.sys.windows.windows only contains a small subset of the
Feb 08 2011
novice2 wrote:That's because the code is derived from MingW, not from the Microsoft headers.one bad (imho) thing - functions parameters names removed :( just types remains. it is make self-documentation or fast-look-to-remember harder :(Wow, I didn't know this existed. I wonder if these bindings would be suitable for inclusion in the core.sys.windows package? Currently, core.sys.windows.windows only contains a small subset of the
Feb 08 2011
I wonder if these bindings would be suitable for inclusion in the core.sys.windows package?They definitely need to be merged.
Feb 08 2011
On 08/02/2011 12:25, Trass3r wrote:Merged? The whole point of the bindings project is that it will one day be complete. As such, it needs to _replace_ the current std.c.windows.* and core.sys.windows.*. Stewart.I wonder if these bindings would be suitable for inclusion in the core.sys.windows package?They definitely need to be merged.
Feb 08 2011
Am 08.02.2011 22:37, schrieb Stewart Gordon:On 08/02/2011 12:25, Trass3r wrote:VisualD has some code for automated winapi-conversion: <quote>to build the necessary D translations from the Windows and Visual Studio SDK</quote> http://www.dsource.org/projects/visuald/wiki/Build_from_source greets MatthiasMerged? The whole point of the bindings project is that it will one day be complete. As such, it needs to _replace_ the current std.c.windows.* and core.sys.windows.*. Stewart.I wonder if these bindings would be suitable for inclusion in the core.sys.windows package?They definitely need to be merged.
Feb 08 2011
Matthias Pleh wrote:Am 08.02.2011 22:37, schrieb Stewart Gordon:Yes, building Visual D uses a tool that machine translates about 40 header and idl files from the Windows SDK (I tweaked it for versions 6.0A and 7.1A) and the full Visual Studio SDK. It filters out unused branches (mostly 64-bit), but tries to keep the rest similar to the original headers including comments. Preprocessor macros with arguments are translated to template functions. It uses "const" for most declaration including GUIDs, so you need to build a library and cannot simply import them in your project. Updating the import libraries needs coffimplib, implib32 does not work well enough. How well does SWIG handle the Windows API headers? Don wrote:On 08/02/2011 12:25, Trass3r wrote:VisualD has some code for automated winapi-conversion: <quote>to build the necessary D translations from the Windows and Visual Studio SDK</quote> http://www.dsource.org/projects/visuald/wiki/Build_from_sourceMerged? The whole point of the bindings project is that it will one day be complete. As such, it needs to _replace_ the current std.c.windows.* and core.sys.windows.*. Stewart.I wonder if these bindings would be suitable for inclusion in the core.sys.windows package?They definitely need to be merged.Andrej Mitrovic wrote:If Walter not only has permission to distribute import libraries, but also the API header files, I could tweak it to support more of the 1200 header files (it often needs one or two special cases per file because of some preprocessor magic), so it could go into the dmd distribution. It is probably not perfectly compatible with core.sys.windows, though. Assuming redistribution is a problem, I was planning to add some conversion wizard to Visual D to let the user create the files from the C headers and libraries. RainerBtw, how up-to-date are the import libs in windows/lib that ships with DMD2? Can they be used with e.g. Win7?They are horribly outdated. But I have a vague recollection that Walter has explicit permission from Microsoft to redistribute updated versions.
Feb 09 2011
Rainer Schuetze wrote:Matthias Pleh wrote:I believe he does. But it was a newsgroup post many years ago, I don't trust my memory on that.Am 08.02.2011 22:37, schrieb Stewart Gordon:Yes, building Visual D uses a tool that machine translates about 40 header and idl files from the Windows SDK (I tweaked it for versions 6.0A and 7.1A) and the full Visual Studio SDK. It filters out unused branches (mostly 64-bit), but tries to keep the rest similar to the original headers including comments. Preprocessor macros with arguments are translated to template functions. It uses "const" for most declaration including GUIDs, so you need to build a library and cannot simply import them in your project. Updating the import libraries needs coffimplib, implib32 does not work well enough. How well does SWIG handle the Windows API headers? Don wrote: > Andrej Mitrovic wrote: >> Btw, how up-to-date are the import libs in windows/lib that ships with >> DMD2? Can they be used with e.g. Win7? > > They are horribly outdated. But I have a vague recollection that Walter > has explicit permission from Microsoft to redistribute updated versions. If Walter not only has permission to distribute import libraries, but also the API header files,On 08/02/2011 12:25, Trass3r wrote:VisualD has some code for automated winapi-conversion: <quote>to build the necessary D translations from the Windows and Visual Studio SDK</quote> http://www.dsource.org/projects/visuald/wiki/Build_from_sourceMerged? The whole point of the bindings project is that it will one day be complete. As such, it needs to _replace_ the current std.c.windows.* and core.sys.windows.*. Stewart.I wonder if these bindings would be suitable for inclusion in the core.sys.windows package?They definitely need to be merged.I could tweak it to support more of the 1200 header files (it often needs one or two special cases per file because of some preprocessor magic), so it could go into the dmd distribution. It is probably not perfectly compatible with core.sys.windows, though. Assuming redistribution is a problem, I was planning to add some conversion wizard to Visual D to let the user create the files from the C headers and libraries. Rainer
Feb 09 2011
On 08/02/2011 22:31, Matthias Pleh wrote: <snip>VisualD has some code for automated winapi-conversion: <quote>to build the necessary D translations from the Windows and Visual Studio SDK</quote><snip> Firstly, can this be used to build D translations from headers other than M$'s own? The win32 translations in the bindings project is based on the MinGW headers, therefore avoiding copyright issues. Secondly, automated translation leaves a lot to be desired, and the whole point of the project is to avoid these shortcomings. Stewart.
Feb 10 2011
Stewart Gordon wrote:On 08/02/2011 22:31, Matthias Pleh wrote: <snip>I guess it can be tweaked without too much effort to work with the MinGW headers. It seems, the mingw-files are missing a lot from the SDK, though. The win32api-3.15 folder has less than 3 MB in <250 files, while the SDK v6.0A which comes with VS2008 has >60MB, just counting the 1200 header files. The current v7.1 has a lot more, but I don't have it on this computer to check.VisualD has some code for automated winapi-conversion: <quote>to build the necessary D translations from the Windows and Visual Studio SDK</quote><snip> Firstly, can this be used to build D translations from headers other than M$'s own? The win32 translations in the bindings project is based on the MinGW headers, therefore avoiding copyright issues.Secondly, automated translation leaves a lot to be desired, and the whole point of the project is to avoid these shortcomings.The mingw win32api files are very terse, so there is not a lot to be lost. But the conversion tool tries to keep comments and formatting as much as possible. Agreed, you can't be sure translation was correct in all cases, but there is so much of it, you don't want to do it manually...
Feb 12 2011
HANDLE WINAPI FindFirstChangeNotification( __in LPCTSTR lpPathName, __in BOOL bWatchSubtree, __in DWORD dwNotifyFilter );FindFirstChangeNotification is - like any other Windows function that receives a string - just an alias that points to a version with suffix W or A depending on whether your project is configured to be Unicode or not.
Feb 08 2011
Trass3r Wrote:D string encoding is not configurable. What configuration are you talking about?HANDLE WINAPI FindFirstChangeNotification( __in LPCTSTR lpPathName, __in BOOL bWatchSubtree, __in DWORD dwNotifyFilter );FindFirstChangeNotification is - like any other Windows function that receives a string - just an alias that points to a version with suffix W or A depending on whether your project is configured to be Unicode or not.
Feb 08 2011
Am 08.02.2011 17:40, schrieb Kagamin:Trass3r Wrote:he talks about stuff like that (from winbase.h - vs2010) WINBASEAPI __out HANDLE WINAPI CreateFileA( __in LPCSTR lpFileName, __in DWORD dwDesiredAccess, __in DWORD dwShareMode, __in_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes, __in DWORD dwCreationDisposition, __in DWORD dwFlagsAndAttributes, __in_opt HANDLE hTemplateFile ); WINBASEAPI __out HANDLE WINAPI CreateFileW( __in LPCWSTR lpFileName, __in DWORD dwDesiredAccess, __in DWORD dwShareMode, __in_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes, __in DWORD dwCreationDisposition, __in DWORD dwFlagsAndAttributes, __in_opt HANDLE hTemplateFile ); #ifdef UNICODE #define CreateFile CreateFileW #else #define CreateFile CreateFileA #endif // !UNICODE not the string itself - look at lpFileName> HANDLE WINAPI FindFirstChangeNotification( > __in LPCTSTR lpPathName, > __in BOOL bWatchSubtree, > __in DWORD dwNotifyFilter > ); FindFirstChangeNotification is - like any other Windows function that receives a string - just an alias that points to a version with suffix W or A depending on whether your project is configured to be Unicode or not.D string encoding is not configurable. What configuration are you talking about?
Feb 08 2011
On Tue, Feb 8, 2011 at 10:40 AM, Kagamin <spam here.lot> wrote:Trass3r Wrote:ceives a string - just an alias that points to a version with suffix W or A= depending on whether your project is configured to be Unicode or not.HANDLE WINAPI FindFirstChangeNotification( =A0 __in=A0=A0LPCTSTR lpPathName, =A0 __in=A0=A0BOOL bWatchSubtree, =A0 __in=A0=A0DWORD dwNotifyFilter );FindFirstChangeNotification is - like any other Windows function that re=D string encoding is not configurable. What configuration are you talking=about?It's a setting in Visual Studio that translates into a compiler switch for Visual C++, or such is my understanding. He was talking about configuration on the Microsoft C/C++ side, not the D side. In D, I just have to add a suffix to the name to choose the one I want.
Feb 08 2011
Am 08.02.2011 17:40, schrieb Kagamin:Trass3r Wrote:or these typical win-api phobos constructs from std.file auto h = useWfuncs ? CreateFileW(std.utf.toUTF16z(name), defaults) : CreateFileA(toMBSz(name), defaults);> HANDLE WINAPI FindFirstChangeNotification( > __in LPCTSTR lpPathName, > __in BOOL bWatchSubtree, > __in DWORD dwNotifyFilter > ); FindFirstChangeNotification is - like any other Windows function that receives a string - just an alias that points to a version with suffix W or A depending on whether your project is configured to be Unicode or not.D string encoding is not configurable. What configuration are you talking about?
Feb 08 2011
Andrew Wiley wrote:I'm trying to use the Windows file change notification API from D, and I'm having trouble translating Microsoft's macro-laden signatures into D. I thought I had it figured out, but optlink says otherwise: The original function is this: HANDLE WINAPI FindFirstChangeNotification( __in LPCTSTR lpPathName, __in BOOL bWatchSubtree, __in DWORD dwNotifyFilter ); I translated it into: extern(Windows) { uint FindFirstChangeNotification( const(char)* lpPathName, bool bWatchSubtree, uint dwNotifyFilter ); } Optlink is giving me undefined symbol errors, but I can't seem to figure out what I have wrong. Any help would be appreciated.Here is the declaration from \dm\include\win32\winbase.h: WINBASEAPI HANDLE WINAPI FindFirstChangeNotificationA( LPCSTR lpPathName, BOOL bWatchSubtree, DWORD dwNotifyFilter ); WINBASEAPI HANDLE WINAPI FindFirstChangeNotificationW( LPCWSTR lpPathName, BOOL bWatchSubtree, DWORD dwNotifyFilter ); #ifdef UNICODE #define FindFirstChangeNotification FindFirstChangeNotificationW #else #define FindFirstChangeNotification FindFirstChangeNotificationA #endif // !UNICODE Note the W postfix and the LPCWSTR arg, which should be wchar* (in D). With the Digital Mars C compiler, getting the de-macro'd version is easy: dmc -c foo.c -e -l and the macro expanded version will be written to foo.lst. Very handy.
Feb 08 2011