File: TypeLib.cpp

package info (click to toggle)
nsis 3.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 12,496 kB
  • sloc: cpp: 39,326; ansic: 27,284; python: 1,386; asm: 712; xml: 409; pascal: 231; makefile: 225; javascript: 67
file content (127 lines) | stat: -rwxr-xr-x 2,109 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*

  NSIS plug-in for Type Library Registration/UnRegistration
  Written by Joost Verburg

  Unicode support by Jim Park -- 08/23/2007

*/

#include <windows.h>
#include <nsis/pluginapi.h> // nsis plugin
#include <nsis/nsis_tchar.h>

#define NSISFunction(funcname) extern "C" void __declspec(dllexport) funcname(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop)

extern "C" BOOL WINAPI DllMain(HINSTANCE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) {
  return TRUE;
}

NSISFunction(Register) {

  EXDLL_INIT();

  wchar_t ole_filename[1024];
  PopStringW(ole_filename);

  ITypeLib* typeLib;
  HRESULT hr;

  hr = LoadTypeLib(ole_filename, &typeLib);

  if (SUCCEEDED(hr)) {

    RegisterTypeLib(typeLib, ole_filename, NULL);

    hr = typeLib->Release();

  }

}

NSISFunction(UnRegister) {

  EXDLL_INIT();

  wchar_t ole_filename[1024];
  PopStringW(ole_filename);

  ITypeLib* typeLib;
  HRESULT hr;

  hr = LoadTypeLibEx(ole_filename, REGKIND_NONE, &typeLib);

  if (SUCCEEDED(hr))
  {

    TLIBATTR* typelibAttr;

    hr = typeLib->GetLibAttr(&typelibAttr);

    if(SUCCEEDED(hr))
    {

      UnRegisterTypeLib(typelibAttr->guid,
        typelibAttr->wMajorVerNum,
        typelibAttr->wMinorVerNum,
        typelibAttr->lcid,
        typelibAttr->syskind);

      typeLib->ReleaseTLibAttr(typelibAttr);

    }

    typeLib->Release();

  }

}

NSISFunction(GetLibVersion) {

  EXDLL_INIT();

  wchar_t ole_filename[1024];
  PopStringW(ole_filename);

  ITypeLib* typeLib;
  HRESULT hr;

  hr = LoadTypeLib(ole_filename, &typeLib);

  if (SUCCEEDED(hr))
  {

    TLIBATTR* typelibAttr;

    hr = typeLib->GetLibAttr(&typelibAttr);

    if (SUCCEEDED(hr))
    {

      TCHAR buf[33];

      wsprintf(buf, _T("%d"), typelibAttr->wMajorVerNum);
      pushstring(buf);
      wsprintf(buf, _T("%d"), typelibAttr->wMinorVerNum);
      pushstring(buf);

      typeLib->ReleaseTLibAttr(typelibAttr);

    }
    else
    {
      pushstring(_T("0"));
      pushstring(_T("0"));
    }

    typeLib->Release();

  }
  else
  {
    pushstring(_T("0"));
    pushstring(_T("0"));
  }

}