1baa3858d3f5d128a5c8466b700098109edcad5f2repo sync// Windows/DLL.h
2baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
3baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#ifndef __WINDOWS_DLL_H
4baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define __WINDOWS_DLL_H
5baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
6baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "../Common/MyString.h"
7baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
8baa3858d3f5d128a5c8466b700098109edcad5f2repo syncnamespace NWindows {
9baa3858d3f5d128a5c8466b700098109edcad5f2repo syncnamespace NDLL {
10baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
11baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#ifdef UNDER_CE
12cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky#define My_GetProcAddress(module, procName) ::GetProcAddressA(module, procName)
13baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#else
14cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky#define My_GetProcAddress(module, procName) ::GetProcAddress(module, procName)
15baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif
16baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
17baa3858d3f5d128a5c8466b700098109edcad5f2repo syncclass CLibrary
18baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
19baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  HMODULE _module;
20baa3858d3f5d128a5c8466b700098109edcad5f2repo syncpublic:
21baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  CLibrary(): _module(NULL) {};
22baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  ~CLibrary() { Free(); }
23baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
24baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  operator HMODULE() const { return _module; }
25baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  HMODULE* operator&() { return &_module; }
26baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  bool IsLoaded() const { return (_module != NULL); };
27baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
28baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  void Attach(HMODULE m)
29baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
30baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    Free();
31baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    _module = m;
32baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
33baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  HMODULE Detach()
34baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
35baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    HMODULE m = _module;
36baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    _module = NULL;
37baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    return m;
38baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
39baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
40cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  bool Free() throw();
41cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  bool LoadEx(CFSTR path, DWORD flags = LOAD_LIBRARY_AS_DATAFILE) throw();
42cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  bool Load(CFSTR path) throw();
43baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  FARPROC GetProc(LPCSTR procName) const { return My_GetProcAddress(_module, procName); }
44baa3858d3f5d128a5c8466b700098109edcad5f2repo sync};
45baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
46cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbeckybool MyGetModuleFileName(FString &path);
47cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky
48cd66d540cead3f8200b0c73bad9c276d67896c3dDavid SrbeckyFString GetModuleDirPrefix();
49baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
50baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}}
51baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
52baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif
53