Implement self-registration of the extension
[git-cheetah/kirill.git] / ext.c
blob593d4e4f5e3dee18c903c1399044517104915176
1 #include <shlobj.h>
2 #include <stdarg.h>
3 #include <tchar.h>
4 #include "ext.h"
5 #include "debug.h"
7 DWORD object_count = 0;
8 DWORD lock_count = 0;
11 * Standard methods for the IUnknown interface:
12 * add_ref, release, query_interface and initialize.
14 * Both of our COM objects contain pointers to the git_data object.
17 inline ULONG STDMETHODCALLTYPE add_ref_git_data(struct git_data *this_)
19 return ++(this_->count);
22 inline ULONG STDMETHODCALLTYPE release_git_data(struct git_data *this_)
24 if (--(this_->count) == 0) {
25 GlobalFree(this_);
26 InterlockedDecrement(&object_count);
27 return 0;
29 return this_->count;
32 inline STDMETHODIMP query_interface_git_data(struct git_data *this_,
33 REFIID iid, LPVOID FAR *pointer)
35 if (IsEqualIID(iid, &IID_git_shell_ext) ||
36 IsEqualIID(iid, &IID_IShellExtInit) ||
37 IsEqualIID(iid, &IID_IUnknown)) {
38 *pointer = &this_->shell_ext;
39 } else if (IsEqualIID(iid, &IID_git_menu) ||
40 IsEqualIID(iid, &IID_IContextMenu)) {
41 *pointer = &this_->menu;
42 } else
43 return E_NOINTERFACE;
45 add_ref_git_data(this_);
46 return NOERROR;
49 inline STDMETHODIMP initialize_git_data(struct git_data *this_,
50 LPCITEMIDLIST folder,
51 LPDATAOBJECT data, HKEY id)
53 FORMATETC format
54 = {CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
55 STGMEDIUM stg = {TYMED_HGLOBAL};
56 HDROP drop;
57 UINT count;
58 HRESULT result = S_OK;
60 if (!data)
61 return S_OK;
63 if (FAILED(data->lpVtbl->GetData(data, &format, &stg)))
64 return E_INVALIDARG;
66 drop = (HDROP)GlobalLock(stg.hGlobal);
68 if (!drop)
69 return E_INVALIDARG;
71 count = DragQueryFile(drop, 0xFFFFFFFF, NULL, 0);
73 if (count == 0)
74 result = E_INVALIDARG;
75 else if (!DragQueryFile(drop, 0, this_->name, sizeof(this_->name)))
76 result = E_INVALIDARG;
78 GlobalUnlock(stg.hGlobal);
79 ReleaseStgMedium(&stg);
81 return result;
85 * Define the shell extension.
87 * Its sole purpose is to be able to query_interface() the context menu.
89 DEFINE_STANDARD_METHODS(git_shell_ext)
91 struct git_shell_ext_virtual_table git_shell_ext_virtual_table = {
92 query_interface_git_shell_ext,
93 add_ref_git_shell_ext,
94 release_git_shell_ext,
95 initialize_git_shell_ext