Update of /cvsroot/pywin32/pywin32/com/win32comext/shell/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2867/win32comext/shell/src
Modified Files:
shell.cpp
Added Files:
PyIQueryAssociations.cpp PyIQueryAssociations.h
Log Message:
Add (client only) support for IQueryAssociations
--- NEW FILE: PyIQueryAssociations.h ---
// This file declares the IPersistFolder Interface and Gateway for Python.
// Generated by makegw.py
// ---------------------------------------------------
//
// Interface Declaration
class PyIQueryAssociations : public PyIUnknown
{
public:
MAKE_PYCOM_CTOR(PyIQueryAssociations);
static IQueryAssociations* GetI(PyObject *self);
static PyComTypeObject type;
// The Python methods
static PyObject *Init(PyObject *self, PyObject *args);
static PyObject *GetKey(PyObject *self, PyObject *args);
static PyObject *GetString(PyObject *self, PyObject *args);
protected:
PyIQueryAssociations(IUnknown *pdisp);
~PyIQueryAssociations();
};
Index: shell.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32comext/shell/src/shell.cpp,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -d -r1.29 -r1.30
*** shell.cpp 9 Oct 2004 01:20:48 -0000 1.29
--- shell.cpp 15 Dec 2004 01:09:13 -0000 1.30
***************
*** 14,17 ****
--- 14,18 ----
#include "shell_pch.h"
+ #include "shlwapi.h"
#include "PyIShellLink.h"
#include "PyIContextMenu.h"
***************
*** 30,33 ****
--- 31,35 ----
#include "PyIDropTargetHelper.h"
#include "PyIAsyncOperation.h"
+ #include "PyIQueryAssociations.h"
#include "PythonCOMRegister.h" // For simpler registration of IIDs etc.
***************
*** 1935,1938 ****
--- 1937,1964 ----
}
+ // @pymethod <o PyIQueryAssociations|shell|AssocCreate|Creates a <o PyIQueryAssociations> object
+ static PyObject *PyAssocCreate(PyObject *self, PyObject *args)
+ {
+ if (!PyArg_ParseTuple(args, ":AssocCreate"))
+ return NULL;
+
+ HMODULE hmod = LoadLibrary(TEXT("shlwapi.dll"));
+ typedef HRESULT (WINAPI * PFNAssocCreate)(CLSID, REFIID, LPVOID);
+ PFNAssocCreate pfnAssocCreate = NULL;
+ if (hmod) pfnAssocCreate=(PFNAssocCreate)GetProcAddress(hmod, "AssocCreate");
+ if (pfnAssocCreate==NULL) {
+ if (hmod) FreeLibrary(hmod);
+ return OleSetOleError(E_NOTIMPL);
+ }
+ HRESULT hr;
+ IQueryAssociations *pRet = NULL;
+ PY_INTERFACE_PRECALL;
+ hr = (*pfnAssocCreate)(CLSID_QueryAssociations, IID_IQueryAssociations, (void **)&pRet);
+ if (hmod) FreeLibrary(hmod);
+ PY_INTERFACE_POSTCALL;
+ if (FAILED(hr))
+ return PyCom_BuildPyException(hr);
+ return PyCom_PyObjectFromIUnknown(pRet, IID_IQueryAssociations, FALSE);
+ }
/* List of module functions */
***************
*** 1940,1943 ****
--- 1966,1970 ----
static struct PyMethodDef shell_methods[]=
{
+ { "AssocCreate", PyAssocCreate, 1 }, // @pymeth AssocCreate|Creates a <o PyIQueryAssociations> object
{ "DragQueryFile", PyDragQueryFile, 1 }, // @pymeth DragQueryFile|Retrieves the file names of dropped files that have resulted from a successful drag-and-drop operation.
{ "DragQueryPoint", PyDragQueryPoint, 1}, // @pymeth DragQueryPoint|Retrieves the position of the mouse pointer at the time a file was dropped during a drag-and-drop operation.
***************
*** 1991,1994 ****
--- 2018,2022 ----
PYCOM_INTERFACE_FULL(ColumnProvider),
PYCOM_INTERFACE_FULL(DropTargetHelper),
+ PYCOM_INTERFACE_CLIENT_ONLY(QueryAssociations),
// IID_ICopyHook doesn't exist - hack it up
{ &IID_IShellCopyHook, "IShellCopyHook", "IID_IShellCopyHook", &PyICopyHook::type, GET_PYGATEWAY_CTOR(PyGCopyHook) },
--- NEW FILE: PyIQueryAssociations.cpp ---
// This file implements the IQueryAssociations Interface and Gateway for Python.
// Generated by makegw.py
#include "shell_pch.h"
#include "shlwapi.h"
#include "PyIQueryAssociations.h"
// @doc - This file contains autoduck documentation
// ---------------------------------------------------
//
// Interface Implementation
PyIQueryAssociations::PyIQueryAssociations(IUnknown *pdisp):
PyIUnknown(pdisp)
{
ob_type = &type;
}
PyIQueryAssociations::~PyIQueryAssociations()
{
}
/* static */ IQueryAssociations *PyIQueryAssociations::GetI(PyObject *self)
{
return (IQueryAssociations *)PyIUnknown::GetI(self);
}
// @pymethod |PyIQueryAssociations|Init|Initializes the IQueryAssociations interface and sets the root key to the appropriate ProgID.
PyObject *PyIQueryAssociations::Init(PyObject *self, PyObject *args)
{
IQueryAssociations *pIQA = GetI(self);
if ( pIQA == NULL )
return NULL;
// @pyparm int|flags||
// @pyparm string|assoc||The string data (ie, extension, prog-id, etc)
// @pyparm <o PyHANDLE>|hkeyProgId|0|
// @pyparm int|hwnd|0|Must be 0
int flags, hwnd=0, hkProgid = 0;
PyObject *obAssoc;
WCHAR *pszAssoc = NULL;
if (!PyArg_ParseTuple(args, "lO|ll:Init", &flags, &obAssoc, &hkProgid, &hwnd))
return NULL;
if (!PyWinObject_AsWCHAR(obAssoc, &pszAssoc, TRUE))
return NULL;
HRESULT hr;
PY_INTERFACE_PRECALL;
hr = pIQA->Init( flags, pszAssoc, (HKEY)hkProgid, (HWND)hwnd);
PyWinObject_FreeWCHAR(pszAssoc);
PY_INTERFACE_POSTCALL;
if ( FAILED(hr) )
return PyCom_BuildPyException(hr, pIQA, IID_IQueryAssociations );
Py_INCREF(Py_None);
return Py_None;
}
// XXX - GetData not implemented - memory management unclear - XXX
// @pymethod int|PyIQueryAssociations|GetKey|Searches for and retrieves a file association-related key from the registry.
PyObject *PyIQueryAssociations::GetKey(PyObject *self, PyObject *args)
{
IQueryAssociations *pIQA = GetI(self);
if ( pIQA == NULL )
return NULL;
// @pyparm int|flags||Used to control the search.
// @pyparm int|assocKey||Specifies the type of key that is to be returned.
// @pyparm string||extra|Optional string with information about the location of the key.
// It is normally set to a shell verb such as 'open'. Set this parameter to None if it is not used.
int flags, assoc;
PyObject *obExtra = Py_None;
HKEY ret = NULL;
WCHAR *pszExtra= NULL;
if (!PyArg_ParseTuple(args, "ll|O:GetKey", &flags, &assoc, &obExtra))
return NULL;
if (!PyWinObject_AsWCHAR(obExtra, &pszExtra, TRUE))
return NULL;
HRESULT hr;
PY_INTERFACE_PRECALL;
hr = pIQA->GetKey( flags, (ASSOCKEY)assoc, pszExtra, &ret);
PyWinObject_FreeWCHAR(pszExtra);
PY_INTERFACE_POSTCALL;
if ( FAILED(hr) )
return PyCom_BuildPyException(hr, pIQA, IID_IQueryAssociations );
return PyLong_FromVoidPtr(ret);
}
// @pymethod int|PyIQueryAssociations|GetString|Searches for and retrieves a file association-related string from the registry.
PyObject *PyIQueryAssociations::GetString(PyObject *self, PyObject *args)
{
IQueryAssociations *pIQA = GetI(self);
if ( pIQA == NULL )
return NULL;
// @pyparm int|flags||Used to control the search.
// @pyparm int|assocStr||Specifies the type of string that is to be returned.
// @pyparm string||extra|Optional string with information about the location of the key.
// It is normally set to a shell verb such as 'open'. Set this parameter to None if it is not used.
int flags, assoc;
PyObject *obExtra = Py_None;
HKEY *ret = NULL;
WCHAR *pszExtra= NULL;
if (!PyArg_ParseTuple(args, "ll|O:GetString", &flags, &assoc, &obExtra))
return NULL;
// @comm Note that ASSOCF_NOTRUNCATE semantics are currently not supported -
// the buffer passed is 2048 bytes long, and will be truncated by the
// shell if too small.
WCHAR result_buf[2048];
DWORD result_size = sizeof(result_buf) / sizeof(result_buf[0]);
if (flags & ASSOCF_NOTRUNCATE)
return PyErr_Format(PyExc_ValueError, "Can not set ASSOCF_NOTRUNCATE - these semantics are not supported");
if (!PyWinObject_AsWCHAR(obExtra, &pszExtra, TRUE))
return NULL;
HRESULT hr;
PY_INTERFACE_PRECALL;
hr = pIQA->GetString( flags, (ASSOCSTR)assoc, pszExtra, result_buf, &result_size);
PyWinObject_FreeWCHAR(pszExtra);
PY_INTERFACE_POSTCALL;
if ( FAILED(hr) )
return PyCom_BuildPyException(hr, pIQA, IID_IQueryAssociations );
// docs don't explicitly say if result_size includes NULL. It says:
// "will be set to the number of characters actually placed in the buffer"
return PyWinObject_FromWCHAR(result_buf, result_size-1);
}
// @object PyIQueryAssociations|Description of the interface
static struct PyMethodDef PyIQueryAssociations_methods[] =
{
{ "Init", PyIQueryAssociations::Init, 1 }, // @pymeth Init|Initializes the IQueryAssociations interface and sets the root key to the appropriate ProgID.
{ "GetKey", PyIQueryAssociations::GetKey, 1 }, // @pymeth GetKey|Searches for and retrieves a file association-related key from the registry.
{ "GetString", PyIQueryAssociations::GetString, 1 }, // @pymeth GetString|Searches for and retrieves a file association-related string from the registry.
{ NULL }
};
PyComTypeObject PyIQueryAssociations::type("PyIQueryAssociations",
&PyIUnknown::type,
sizeof(PyIQueryAssociations),
PyIQueryAssociations_methods,
GET_PYCOM_CTOR(PyIQueryAssociations));
|