4

Given an appropriate manifest that sets uiAccess="true", should a win32 program (that works fine on other Windows7 systems) be able to get a valid handle back from SetWindowsHookEx when running on Windows7 (32bit) on Mac Mini using Parallels ?

This is the line of Delphi XE4 code that calls the API

HookHandle := SetWindowsHookEx(WH_JOURNALPLAYBACK, @Playback, hInstance, 0);

I keep getting "access denied" as the system error returned in HookHandle.

I have tried many variations of my manifest syntax and am seriously wondering whether this is just some limitation of the Mac Mini / Parallels environment. The user invoking the program is an Administrator. UAC is enabled. I have tried Run as Administrator; no difference.

My manifest file follows.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity   type="win32" name="FFHotKeys" version="1.1.0.0  processorArchitecture="*"/>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level="asInvoker" uiAccess="true"/>
      </requestedPrivileges>
    </security>
  </trustInfo>
  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
    <application>
      <!--The ID below indicates application support for Windows 7 -->
      <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
    </application>
  </compatibility>
</assembly>

I have tried stting the level to each of these

level="asInvoker"
level="requireAdministrator"
level="highestAvailable"

and that did not solve the 'access denied' problem.

Note: I am including my manifest via .rc file containing

1 24 "FFHotKeys.exe.manifest"

rather than by the Custom Manifest feature under Project > Options. I have "Enable Runtime Themes" and a blank custom manifest. I tried it the other way but with slightly different .manifest contents.

Note: when I check the resources with XN_Resource_Editor, there is an "XP Theme Manifest" resource containing exactly the XML expected. There are also 2 VCLSTYLE resources. Thank you.

RRUZ
  • 134,889
  • 20
  • 356
  • 483
user424855
  • 233
  • 1
  • 2
  • 8
  • 2
    Windows 7 is Windows 7, so I don't see why the emulator should be a factor. – Jonathan Potter Sep 10 '13 at 08:24
  • You understand that this hook is a global hook right? What has `uiAccess` got to do with this? – David Heffernan Sep 10 '13 at 08:28
  • @DavidHeffernan: I got the uiAccess idea from http://stackoverflow.com/questions/9165666/setwindowshookex-for-wh-journalrecord-fails-under-vista-windows-7 and http://www.autohotkey.com/board/topic/46502-sendplay-and-windows-7-doesnt-work-together/ where it says "To set a Journal hook, the app needs to be signed, manifested for uiAccess, and run from a secure location (usually Program Files)." I did move the exe to c:\Program Files\, and I did code-sign it. – user424855 Sep 10 '13 at 08:45
  • Fair enough. Tag list changed. It is possible that I am setting the manifest incorrectly in Delphi XE4. I did not have good results using the built-in Project > Options, Application, Runtime Themes, Custom Manifest feature so I just bound the .manifest file in as a resource. Hence wanting to know if it *should* work. – user424855 Sep 10 '13 at 09:14
  • 1
    Are you sure about `processorArchitecture="*"`? I seem to recall trying that once and finding problems. My code uses amd64 or X86 as applicable. Also, it's not obvious that the module handle you pass is in a DLL and not in the app. – David Heffernan Sep 10 '13 at 09:29
  • I tried X86 once but not with that being the only change. I can connect to the problem machine again in about 12 hours so I will confirm then. The module handle is within the app and the function in question is declared with stdcall; export; – user424855 Sep 10 '13 at 09:48

1 Answers1

1

The answer is YES, it should and does work on Parallels.

The problem was clarified by using XN_Resource_Editor to examine the compiled EXE. Turns out the only deleting the .RES file prior to Project > Build led to the resources being recompiled, so test results had been confusing. More importantly, Delphi XE4 uses its default manifest when RunTime themes are involved. Therefore the solution was to delete the resource references in the project and instead use Project > Options, Application, Runtime Themes, select the custom manifest and then Project > Build and code-sign the EXE and run it from under c:\Program Files\subdir.

processorArchitecture="*" 

was valid in the manifest

<requestedExecutionLevel level="asInvoker" uiAccess="true"/>

was valid in the manifest.

user424855
  • 233
  • 1
  • 2
  • 8