Recently I decided to try to incorporate Windows Job Objects into a project to artificially limit the amount of memory available to an application so I could test it’s behaviour under such circumstances. Originally I had intended on using M$’s Application Verifier for that purpose, but it lacks any real documentation, and apparently does not provide this exact functionality (the low resource utilization provides random failures).
I thought I would use the JWSCL library since it has a class that wraps Job Objects. Getting it to compile was unfortunately not so straightforward.
To start with, the JWSCL requires the JWA library, so you need to get that compiled first. I had no luck compiling the downloaded version so I pulled the current source from the trunk. Then I followed the READMEFIRST.txt file for the JWA library, but got a compilation error:
E1025 Unsupported language feature: 'import of DLL symbol by ordinal' "
Googling this I stumbled across a reply to a post from Peter Below explaining “This is caused by a change in defaults for the project options. Call up the options dialog, select the Output - C/C++ page, and make sure the “C/C++ output file generation” entry is set to “Generate DCUs only”. I toggled the option, and voila! The JWA compiled.
Then I tried the JWSCL and got a “[dcc32 Error] JwsclLsa.pas(121): E2010 Incompatible types: ‘Cardinal’ and ‘NativeUInt’. Seems that a THandle is used for some definitions and equates to a NativeInt in XE4, but in other places handles are defined as Cardinals. TJwSecurityLsa uses a mixed definition of a property and changing it to use THandle just opens up the proverbial rabbit hole.
I ended up abandoning my attempt to get JWSCL compiling in part because I downloaded another implementation of the Job Object API from here. Thanks ZigiZ. It’s unfortunate that such libraries are so difficult to maintain for multiple compilers. I know from personal experience with hcOPF that it is very difficult to change a library and maintain a good user experience for developers using a multitude of Delphi versions.
Now if only I could find out if it is possible to add a process to a job from that process (I get a security error)