By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,384 Members | 2,062 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,384 IT Pros & Developers. It's quick & easy.

cddb and mci produce an ImportError

P: n/a
Hi,

i am in search of a cddb module for Python on windows. I stumbled upon
http://sourceforge.net/projects/cddb-py but couldn't use it since the
mci.dll is compiled against Python2.0.
So i'm trying to rebuild it using Dev-C++. I've succeeded in building a
dll but when i try a test program it get this error:
http://sourceforge.net/projects/cddb-py

Traceback (most recent call last):
File "cddtest.py", line 1, in ?
import CDDB, DiscID
File "C:\Python24\lib\DiscID.py", line 15, in ?
import cdrom, sys
File "C:\Python24\lib\cdrom.py", line 8, in ?
import mci
ImportError: dynamic module does not define init function (initmci)

I had already some problems with the CDDB.py program since it used
os.geteuid() and python gave an error for that too. These are the files
i'm using and i'm not sure the content is correct. I used a dll project
and copied and pasted the content of the original files from the cddb
project in there in the hopes of getting it to work.

mci.h
================================================== ======================
#ifndef _DLL_H_
#define _DLL_H_

#if BUILDING_DLL
# define DLLIMPORT __declspec (dllexport)
#else /* Not BUILDING_DLL */
# define DLLIMPORT __declspec (dllimport)
#endif /* Not BUILDING_DLL */

DLLIMPORT void initmci(void);

class DLLIMPORT DllClass
{
public:
DllClass();
virtual ~DllClass(void);

private:

};
#endif /* _DLL_H_ */
mci.cpp
================================================== ======================
/* Replace "dll.h" with the name of your header */
#include "mci.h"
#include <windows.h>
#include <mmsystem.h>
#include <C:\Python24\include\Python.h>

DllClass::DllClass()
{

}
DllClass::~DllClass ()
{

}

static PyObject *mci_error;

#define MCI_STRING_LEN 1000

static PyObject *mci_mciSendString(PyObject *self, PyObject *args)
{
char resultStr[MCI_STRING_LEN+1];
PyObject *pyStr = 0;
if (!PyArg_ParseTuple(args, "O!", &PyString_Type, &pyStr))
return NULL;
// windows mciSendString see cdrom.py for Samples (or MSDN for
complete doc)
mciSendString( PyString_AsString(pyStr), resultStr,MCI_STRING_LEN,0);
return Py_BuildValue("s", resultStr);
}
static PyMethodDef mci_methods[] = {
{ "mciSendString", mci_mciSendString, METH_VARARGS },
{ NULL, NULL }
};
void initmci(void)
{
PyObject *module, *dict;

module = Py_InitModule("mci", mci_methods);
dict = PyModule_GetDict(module);
mci_error = PyErr_NewException("mci.error", NULL, NULL);
PyDict_SetItemString(dict, "error", mci_error);
}

BOOL APIENTRY DllMain (HINSTANCE hInst /* Library instance handle. */ ,
DWORD reason /* Reason this function
is being called. */ ,
LPVOID reserved /* Not used. */ )
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
break;

case DLL_PROCESS_DETACH:
break;

case DLL_THREAD_ATTACH:
break;

case DLL_THREAD_DETACH:
break;
}

/* Returns TRUE on success, FALSE on failure */
return TRUE;
}

test program
================================================== ======================
import CDDB, DiscID

cdrom = DiscID.open()
disc_id = DiscID.disc_id(cdrom)

(query_status, query_info) = CDDB.query(disc_id)
(read_status, read_info) = CDDB.read(query_info['category'],
query_info['disc_id'])

for i in range(disc_id[1]):
print "Track %.02d: %s" % (i, read_info['TTITLE' + `i`])

I've included these libraries (linker options):
--no-export-all-symbols --add-stdcall-alias
C:/Dev-Cpp/lib/libwinmm.a
C:/Python24/libs/python24.lib
C:/Python24/libs/libpython24.a

It compiles fine and makes a mci.dll but as i said, i get the
ImportError when i run it.

Any ideas?

Thanks,
Benedict
Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
flupke wrote:
<snip>

I finally succeeded in making a proper mci.dll that works. I will
document what i did in the coming days and place it here. I developed
the dll with DevC++.
Anyway, it all works :)

Benedict
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.