views:

903

answers:

3

I have a couple of questions as below. CHM is (Compiled HTML File)

My CHM file has a link to launch a 32-bit application. The CHM file is coded in Javascript.This works fine in a 32-bit OS environment.

But this does not work in a 64 bit OS environment.The reason being: When I open the chm file,64-bit version of hh.exe(an operating system executable) executes and launches the chm. And the chm gets loaded in a 64-bit environment.
And now I cannot launch the 32 bit application from the CHM file, because a 64-bit process cannot load a 32-bit process.

Is there any way I can make it work for 64-bit OS as well ?

I thought of few solutions as below but I dont know how to implement them .

1)In Javascript code,if I could check whether the OS is a 32-bit or 64 bit.Then I could pop-up a well-defined error to user,if it is 64-bit OS.

2)Or if I could force the OS to run the 32-bit version of hh.exe, so that the chm is loaded in a 32-bit environment and hence causing no problem.

A: 

Or 3) distribute a 64-bit version of the application launched by the CHM?

RobS
The problem with this is that it would not work in a 32-bit environment. And we cannot have multiple versions of the application.And even if we have both versions available for the application,how would Java Script know which one to launch.
Rakesh Agarwal
Assuming you could have a 32 and 64 bit version, I'd suggest you'd distribute the correct edition to the correct platform. Given you can't then launching the 32bit version hh.exe might be your only option.
RobS
A: 

You need to execute the 32 bits version of hh.exe. To do this launch the hh.exe with this path %WINDIR%\System32\hh.exe but before launching the application you must disable the Wow64 file system redirection.

Here you have an example:

#define _WIN32_WINNT 0x0501
#include <Windows.h>

void main()
{
 PVOID OldValue;
 HANDLE hFile = INVALID_HANDLE_VALUE;

 BOOL bRet = Wow64DisableWow64FsRedirection (&OldValue);

 if (bRet == TRUE) 
 {
  // Open a file

  hFile = CreateFile(TEXT("C:\\Windows\\System32\\Notepad.exe"),
   GENERIC_READ,
   FILE_SHARE_READ,
   NULL,
   OPEN_EXISTING,
   FILE_ATTRIBUTE_NORMAL,
   NULL);

  // Restore the previous WOW64 file system redirection value.

  Wow64RevertWow64FsRedirection (OldValue);
 }

 if( INVALID_HANDLE_VALUE != hFile )  
 {
  // Use the file handle
 }
}

NOTE: Remember to revert the redirection after you call the application

xgoan
+1  A: 

And now I cannot launch the 32 bit application from the CHM file, because a 64-bit process cannot load a 32-bit process

Not sure what you mean by 'load a 32-bit process', but a 32-bit process can most certainly create a 64-bit process. For example, if I have MyApp32.exe, a 32-bit application, it can absolutely launch MyApp64.exe, a 64-bit application.

When you read about incompatibilities between 32- and 64-bit code, it refers to a 32-bit application loading a 64-bit DLL, or vice versa.

I suspect your problem is actually the path you are using to launch the application is running afoul of the WOW64 file system redirection. In this scheme, 32-bit applications that access C:\Windows\System32, are actually redirected to C:\Windows\SysWow64\System32. You can read about that more here

If that doesn't work, more information about how you are launching this 32-bit process and where it is located on the file system might add some clarity.

anelson