Python extension: SHAppBarMessage in VC++ .. help?

Keith Farmer deoradh at yahoo.com
Sat Jun 23 05:32:38 EDT 2001


This is only my 2nd extension for Python I've written.  The idea is to
provide an interface to the SHAppBarMessage function in Win32, which takes
an APPBARDATA struct as its second argument, itself having a RECT struct:

typedef struct _AppBarData {
 DWORD cbSize;
 HWND hWnd;
 UINT uCallbackMessage;
 UINT uEdge;
 RECT rc;
 LPARAM lParam;
} APPBARDATA,*PAPPBARDATA;

Here's the file:

.....

/* appbar.cpp -- appbar functionality
*/

#include "Python.h"
#include <math.h>
#include <shellapi.h>
//#include <shlguid.h>
//#include <shlobj.h>

static PyObject *AppBarError;

static PyObject *AppBar_SHAppBarMessage(PyObject *self, PyObject *args)
{

 int result;
 UINT msg;
 APPBARDATA abd;

 if (!PyArg_ParseTuple(args,
       "IPIII(iiii)",
       &msg,      // UINT
       &(abd.hWnd),    // HWND
       &(abd.uCallbackMessage), // UINT
       &(abd.uEdge),    // UINT
       &(abd.lParam),    // LPARAM
       &(abd.rc.left),    // int
       &(abd.rc.top),    // int
       &(abd.rc.right),   // int
       &(abd.rc.bottom)   // int
      ))
  return NULL;

 abd.cbSize = sizeof(abd);

 if (SHAppBarMessage(msg, &abd))
  result = 1;
 else
  result = 0;

 return Py_BuildValue("(l(iiii))", result, abd.rc.left, abd.rc.top,
abd.rc.right, abd.rc.bottom);
}

static PyMethodDef AppBarMethods[] = {
 { "SHAppBarMessage", AppBar_SHAppBarMessage, METH_VARARGS },
 { NULL, NULL }    /* Sentinel */
};

#ifdef MS_WIN32
__declspec(dllexport)
#endif

void initAppBar()
{
 PyObject *m, *d;

 m = Py_InitModule("AppBar", AppBarMethods);
 d = PyModule_GetDict(m);
 AppBarError = PyErr_NewException("AppBar.error", NULL, NULL);
 PyDict_SetItemString(d, "error", AppBarError);
}

.....

And here are the errors so far:

c:\program files\microsoft visual studio\vc98\include\shellapi.h(53) : error
C2065: 'HDROP' : undeclared identifier
c:\program files\microsoft visual studio\vc98\include\shellapi.h(53) : error
C2501: 'DECLARE_HANDLE' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\shellapi.h(55) : error
C2146: syntax error : missing ';' before identifier 'UINT'
c:\program files\microsoft visual studio\vc98\include\shellapi.h(55) : error
C2501: 'DECLSPEC_IMPORT' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\shellapi.h(55) : fatal
error C1004: unexpected end of file found

Now, I'm not even certain that I'm doing this in the correct manner.  I gave
up trying to figure out how to calldll the function, trying to set up a
struct using the python module.  I'm not even certain I know how to go about
testing this -- my C experience has historically been mundane, and on Unix.

Keith Farmer





More information about the Python-list mailing list