ImageMagick 加载 dll 相关的源代码

根据 NTLoadLibrary() 的源代码,可以看出,  ImageMagick 内部使用的是 utf-8 编码,并且 NTLoadLibrary() 在加载 dll 的时候,先将 dll 的路径 转换成 wchar_t, 然后使用 LoadLibraryExW() 加载 dll

static inline void *NTLoadLibrary(const char *filename)
{
  int
    length;

  wchar_t
    path[MaxTextExtent];

  length=MultiByteToWideChar(CP_UTF8,0,filename,-1,path,MaxTextExtent);
  if (length == 0)
    return((void *) NULL);
  return (void *) LoadLibraryExW(path,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
}

MagickPrivate void *NTOpenLibrary(const char *filename)
{
  char
    path[MaxTextExtent];

  register const char
    *p,
    *q;

  UINT
    mode;

  void
    *handle;

  mode=ChangeErrorMode();
  handle=NTLoadLibrary(filename);
  if (handle == (void *) NULL)
    {
      p=GetSearchPath();
      while (p != (const char*) NULL)
      {
        q=strchr(p,DirectoryListSeparator);
        if (q != (const char*) NULL)
          (void) CopyMagickString(path,p,q-p+1);
        else
          (void) CopyMagickString(path,p,MaxTextExtent);
        (void) ConcatenateMagickString(path,DirectorySeparator,MaxTextExtent);
        (void) ConcatenateMagickString(path,filename,MaxTextExtent);
        handle=NTLoadLibrary(path);
        if (handle != (void *) NULL || q == (const char*) NULL)
          break;
        p=q+1;
      }
    }
  SetErrorMode(mode);
  return(handle);
}
原文地址:https://www.cnblogs.com/personnel/p/12321634.html