[python-win32] Urgent Help reg DLLs

Jens B. Jorgensen jens.jorgensen at tallan.com
Mon Sep 29 13:50:47 EDT 2003


In this same vein there is another project, ctypes, which also aims to 
provide a generalized solution to calling binary shared objects (dlls on 
windows, .so on linux, etc.) which is pretty active and stable. You can 
check it out at http://sourceforge.net/projects/ctypes/

I didn't suggest it here because if indeed you are calling a .dll that 
comes from a C++ project and exports the actual objects and member 
functions then you'll have to deal with c++ name "decoration" and 
under-the-cover details about how objects get constructed, etc. which 
are probably more trouble than they are worth. If the functions you're 
calling are instead "bare" c functions then using the solution below or 
cyptes would certainly be the easiest route to go.

Larry Bates wrote:

>You should check out:
>
>http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146847
>
>This is a general purpose class wrapper for calling any
>arbitrary .DLL (and associated functions in that .DLL).
>
>I've used to it to call may different Windows .DLL files.
>
>Good luck.
>
>-Larry
>
>------------------------------
>
>Message: 5
>Date: Mon, 29 Sep 2003 13:25:29 +0800
>From: "Sachin S.Suresh" <sureshsubbiah at india.com>
>Subject: [python-win32] Urgent Help reg DLLs
>To: python-win32 at python.org
>Message-ID: <20030929052529.19357.qmail at india.com>
>Content-Type: text/plain; charset="iso-8859-1"
>
>
>hi all,
>I'm developing our tool using python 2.2.2.
>I  need to use a function which is defined a seperate DLL file named
>"common.dll". My problem is, i need to create an object for a class which is in
>the DLL file to access the member function of that class in DLL.
>
>The Structure of Class in DLL is,
>
>class Common
>{
>
>  int Result;
>  int ToServer(address,message);
>}.
>
>Thatz it. I need to access that member funcion ToServer.
>Plz help me out in this case. Its a bit urgent.
>
>Expecting useful stuff from all of u group mates.
>
>Thanx a lot in advance !
>
>
>
>Keeeeeeeeeeep (s)mailing
>Sachin S.Suresh
>
>"A diamond is just another piece of coal that did well under pressure"
>
>
>
>--
>______________________________________________
>http://www.india.com
>Now with POP3/SMTP access for only US$14.95/yr
>
>Powered by Outblaze
>
>
>
>------------------------------
>
>Message: 6
>Date: Mon, 29 Sep 2003 16:12:40 +0200
>From: Samuel Lacas <Samuel.Lacas at trusted-logic.fr>
>Subject: [python-win32] error in win32com source ?
>To: python-win32 at python.org
>Message-ID: <20030929161240.A25782 at ouessant.trusted-logic.fr>
>Content-Type: text/plain; charset=us-ascii
>
>Hello,
>
>I don't know whether it is an error or there is a reason behind this,
>but I wonder about the following: in the RegisterClasses function of
>the win32com.server.register module, we have this line (371st for me):
>
>    addnPath = None
>
>According to the documentation (see RegisterServer earlier in the
>module), this parameter should allow someone to provide an additional
>search path for the server when registering it; but the previous line
>obviously disables the feature.
>
>Is there a reason for this ?
>
>sL
>
>
>
>------------------------------
>
>Message: 7
>Date: Mon, 29 Sep 2003 09:50:59 -0500
>From: "Jens B. Jorgensen" <jens.jorgensen at tallan.com>
>Subject: Re: [python-win32] Urgent Help reg DLLs
>To: "Sachin S.Suresh" <sureshsubbiah at india.com>
>Cc: python-win32 at python.org
>Message-ID: <3F7846D3.5050706 at tallan.com>
>Content-Type: text/plain; charset="iso-8859-1"
>
>You should be able to build a c++ extension dll that wraps the c++
>class. The on-line documentation for Python includes a nice tutorial and
>introduction for extending python (look under "Extending and
>Embedding"). If you have the distutils module installed it is especially
>easy. Let's say you want to call your new module pyCommonWrap. You
>create a c++ source file calld pyCommonWrap.cpp like so:
>
>#include <Python.h>
>#include <my header file describing common.dll>
>
>PyObject *pyCommonWrap_ToServer(PyObject *self, PyObject *args)
>{
>    char *address, *message;
>    // note that you didn't give complete type info for Common so I'm
>assuming here that those
>    // args are both const char *
>    if (!PyArg_ParseTuple(args, "ss", &address, &message))
>       return NULL;
>
>    Common cmn;
>    int result = cmn.ToServer(address, message);
>
>    return PyInt_FromLong(result);
>}
>
>PyMethodDef pyCommonWrap_methods[] = {
>    {"ToServer", pyCommonWrap_ToServer, METH_VARARGS, "ToServer(address,
>message) ==> result"},
>    {NULL, NULL}
>};
>
>extern "C" __declspec(dllexport)
>void initpyCommonWrap(void)
>{
>    Py_InitModule("pyCommonWrap", pyCommonWrap_methods);
>}
>
>
>And to make the compiling and all that easy (and supposing you have
>distutils) you now create a python file named setup.py containing:
>
>from distutils.core import setup, Extension
>
>ext = Extension("pyCommonWrap", ["pyCommonWrap.cpp"])
>
>setup(name = "pyCommonWrap", version = "0.1", description = "wrapper lib
>for common.dll", ext_modules = [ext])
>
>And now you're ready to compile your module:
>
>python setup.py install
>
>And that will build your module and install it into your python
>site-packages sub-dir so you can find it. You can now test your module.
>Invoke Python and type:
>
>import pyCommonWrap
>
>print pyCommonWrap.ToServer("an address", "a message")
>
>
>That's the basics of it. Seriously though you should have considered
>reading the fine manual before such a post as this. Anyway I haven't
>tested any of the above, just typed it in, so naturally there will be
>some tweaks necessary here and there.
>
>
>Sachin S.Suresh wrote:
>
>  
>
>>hi all,
>>I'm developing our tool using python 2.2.2.
>>I  need to use a function which is defined a seperate DLL file named
>>    
>>
>"common.dll". My problem is, i need to create an object for a class which is in
>the DLL file to access the member function of that class in DLL.
>  
>
>>The Structure of Class in DLL is,
>>
>>class Common
>>{
>>
>> int Result;
>> int ToServer(address,message);
>>}.
>>
>>Thatz it. I need to access that member funcion ToServer.
>>Plz help me out in this case. Its a bit urgent.
>>
>>Expecting useful stuff from all of u group mates.
>>
>>Thanx a lot in advance !
>>
>>
>>
>>Keeeeeeeeeeep (s)mailing
>>Sachin S.Suresh
>>
>>"A diamond is just another piece of coal that did well under pressure"
>>
>>
>>
>>
>>
>>    
>>
>
>--
>Jens B. Jorgensen
>jens.jorgensen at tallan.com
>
>"With a focused commitment to our clients and our people, we deliver value
>through customized technology solutions."
>
>-------------- next part --------------
>A non-text attachment was scrubbed...
>Name: smime.p7s
>Type: application/x-pkcs7-signature
>Size: 3108 bytes
>Desc: S/MIME Cryptographic Signature
>Url :
>http://mail.python.org/pipermail/python-win32/attachments/20030929/900ddd9d/smim
>e-0001.bin
>
>------------------------------
>
>_______________________________________________
>Python-win32 mailing list
>Python-win32 at python.org
>http://mail.python.org/mailman/listinfo/python-win32
>
>
>End of Python-win32 Digest, Vol 6, Issue 11
>*******************************************
>
>
>
>_______________________________________________
>Python-win32 mailing list
>Python-win32 at python.org
>http://mail.python.org/mailman/listinfo/python-win32
>  
>

-- 
Jens B. Jorgensen
jens.jorgensen at tallan.com

"With a focused commitment to our clients and our people, we deliver value through customized technology solutions."

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3108 bytes
Desc: S/MIME Cryptographic Signature
Url : http://mail.python.org/pipermail/python-win32/attachments/20030929/29da8bbd/smime.bin


More information about the Python-win32 mailing list