Fix .h-files to not define variables
[git-cheetah/kirill.git] / ext.c
blob69777d3cd235a20a5a0ed85e0cf666c6865f2672
1 #include <shlobj.h>
2 #include <stdarg.h>
3 #include <tchar.h>
4 #include "ext.h"
5 #include "debug.h"
6 #include "systeminfo.h"
8 DWORD object_count = 0;
9 DWORD lock_count = 0;
12 * Standard methods for the IUnknown interface:
13 * add_ref, release, query_interface and initialize.
15 * Both of our COM objects contain pointers to the git_data object.
18 inline ULONG STDMETHODCALLTYPE add_ref_git_data(struct git_data *this_)
20 return ++(this_->count);
23 inline ULONG STDMETHODCALLTYPE release_git_data(struct git_data *this_)
25 if (--(this_->count) == 0) {
26 GlobalFree(this_);
27 InterlockedDecrement(&object_count);
28 return 0;
30 return this_->count;
33 inline STDMETHODIMP query_interface_git_data(struct git_data *this_,
34 REFIID iid, LPVOID FAR *pointer)
36 if (IsEqualIID(iid, &IID_git_shell_ext) ||
37 IsEqualIID(iid, &IID_IShellExtInit) ||
38 IsEqualIID(iid, &IID_IUnknown)) {
39 *pointer = &this_->shell_ext;
40 } else if (IsEqualIID(iid, &IID_git_menu) ||
41 IsEqualIID(iid, &IID_IContextMenu)) {
42 *pointer = &this_->menu;
43 } else
44 return E_NOINTERFACE;
46 add_ref_git_data(this_);
47 return NOERROR;
50 inline STDMETHODIMP initialize_git_data(struct git_data *this_,
51 LPCITEMIDLIST folder,
52 LPDATAOBJECT data, HKEY id)
54 FORMATETC format
55 = {CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
56 STGMEDIUM stg = {TYMED_HGLOBAL};
57 HDROP drop;
58 UINT count;
59 HRESULT result = S_OK;
61 /* if we can't find msysPath, don't even try to do anything else */
62 if (!msys_path())
63 return E_NOTIMPL;
65 /* store the folder, if provided */
66 if (folder)
67 SHGetPathFromIDList(folder, this_->name);
69 if (!data)
70 return S_OK;
72 if (FAILED(data->lpVtbl->GetData(data, &format, &stg)))
73 return E_INVALIDARG;
75 drop = (HDROP)GlobalLock(stg.hGlobal);
77 if (!drop)
78 return E_INVALIDARG;
80 count = DragQueryFile(drop, 0xFFFFFFFF, NULL, 0);
82 if (count == 0)
83 result = E_INVALIDARG;
84 else if (!DragQueryFile(drop, 0, this_->name, sizeof(this_->name)))
85 result = E_INVALIDARG;
87 GlobalUnlock(stg.hGlobal);
88 ReleaseStgMedium(&stg);
90 return result;
94 * Define the shell extension.
96 * Its sole purpose is to be able to query_interface() the context menu.
98 DEFINE_STANDARD_METHODS(git_shell_ext)
100 struct git_shell_ext_virtual_table git_shell_ext_virtual_table = {
101 query_interface_git_shell_ext,
102 add_ref_git_shell_ext,
103 release_git_shell_ext,
104 initialize_git_shell_ext