OCX文件上的LoadLibrary失败

OCX文件上的LoadLibrary失败

本文介绍了在Windows 7 x64中,OCX文件上的LoadLibrary失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从用旧版C ++ Builder编写的旧版Windows应用程序中打开一个html帮助文件. HtmlHelp是通过HtmlHelp.ocx加载的,我是通过LoadLibrary加载的.

I need to open a html help file from within a legacy windows application written in old version of C++ Builder. HtmlHelp is loaded via HtmlHelp.ocx, which I am loading via LoadLibrary.

这已经工作了好多年,但是在Windows 7 x64中不再起作用了.在Windows7 x86下它也可能会失败,但是我没有任何装有此操作系统的计算机,因此目前无法尝试.

This has worked fine for years, but it does not work anymore in Windows 7 x64. It might also fail under Windows7 x86, but I don't have any computer with this OS, so I can't try it out at the moment.

我正在动态加载hhctrl.ocx,如下所示:

I am loading hhctrl.ocx dynamically as follows:

#define HHPathRegKey "CLSID\\{adb880a6-d8ff-11cf-9377-00aa003b7a11}\\InprocServer32"

bool THTMLHelper::LoadHtmlHelp()
{
  HKEY HHKey;
  DWORD PathSize = 255;
  char Path[255];
  bool R = false;

  if (::RegOpenKeyExA(HKEY_CLASSES_ROOT, HHPathRegKey, 0, KEY_QUERY_VALUE, (void **)&HHKey) == ERROR_SUCCESS)
  {
    if (::RegQueryValueExA(HHKey, "", NULL, NULL, (LPBYTE)Path, &PathSize) == ERROR_SUCCESS)
    {
      //*****************************************
      //LOADING FAILS HERE
      //PATH IS %SystemRoot%\System32\hhctrl.ocx
      //*****************************************
      HHLibrary = ::LoadLibrary(Path);
      if (HHLibrary != 0)
      {
        __HtmlHelp = (HTML_HELP_PROC) ::GetProcAddress(HHLibrary, "HtmlHelpA");
        R = (__HtmlHelp != NULL);
        if (!R)
        {
          ::FreeLibrary(HHLibrary);
          HHLibrary = 0;
        }
      }
    }
    ::RegCloseKey(HHKey);
  }
  return R;
}

我检查了Windows 7系统上是否存在%SystemRoot%\ System32 \ hhctrl.ocx,并且确实存在.

I checked if %SystemRoot%\System32\hhctrl.ocx exists on the Windows 7 system and it does.

为什么通过LoadLibrary加载失败?我该如何解决这个问题?

Why does loading it via LoadLibrary fail? How can I work around this problem?

编辑:GetLastError说(德语,所以我只是翻译):找不到文件."但是我调试了该函数,并且路径为%SystemRoot%\ System32 \ hhctrl.ocx",并且该文件确实存在.

GetLastError says (in German, so I am just translating): "Could not find file." But I debugged the function and the path is "%SystemRoot%\System32\hhctrl.ocx" and the file does exist.

此外,由于有两个答案指向64位和32位问题:我的应用程序是在C ++ Builder 5中编译的32位可执行文件,因此如果我没有记错的话,它应该是32位进程.还是我认为那是错误的?

Also, since two answers point in the direction of 64-bit vs 32-bit problems: My application is a 32 bit executable compiled in C++ Builder 5, so it should be a 32 bit process if I'm not mistaken. Or am I wrong to assume that?

推荐答案

使用 ExpandEnvironmentStrings 函数可将%SystemRoot%\ System32 \ hhctrl.ocx扩展为用户安装时的真实路径. 64位操作系统将正确地将扩展路径重定向到32位dll.

Use ExpandEnvironmentStrings function to expand %SystemRoot%\System32\hhctrl.ocx to real path on user's intallation. 64bit OS will redirect expanded path to 32bit dll correctly.

这篇关于在Windows 7 x64中,OCX文件上的LoadLibrary失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 00:33