#include "python2.4/Python.h" #include #include #include #include #define BUFFERSIZE 4096 static PyObject * playsound(PyObject *self, PyObject *args) { void *sound; UINT soundlength; UINT flags; BOOL status; if (!PyArg_ParseTuple(args, "s#i", &sound, &soundlength, &flags)) { PyErr_SetString(PyExc_SyntaxError, "Expected (string, long)"); return NULL; } status = sndPlaySound(sound, flags); return Py_BuildValue("i", status); } static PyObject * beep(PyObject *self, PyObject *args) { BOOL status; DWORD duration, frequency; if (!PyArg_ParseTuple(args, "ii", &duration, &frequency)) { frequency = 440; /* A above middle C by default */ if (!PyArg_ParseTuple(args, "i", &duration)) { duration = 500; /* 1/2 second by default */ } } PyErr_Clear(); /* ignore any failures above */ status = Beep(duration, frequency); return Py_BuildValue("i", status); } static PyMethodDef winsoundMethods[] = { {"PlaySound", playsound, METH_VARARGS, "Play WAV-format sounds"}, {"Beep", beep, METH_VARARGS, "Simple console beep"}, {NULL, NULL, 0, NULL} }; PyMODINIT_FUNC init_winsound(void) { (void) Py_InitModule("_winsound", winsoundMethods); }