Discussion:
[Python.NET] Use of c++ dll in python
Lalit DIGARI
2006-04-03 11:22:05 UTC
Permalink
Hello All ,
I have devloped a c++ dll named mydll in c++ how can I access it with in python script using ctype...
Regard's
Lalit

_________________________________________________
Python.NET mailing list - PythonDotNet-+ZN9ApsXKcEdnm+***@public.gmane.org
http://mail.python.org/mailman/listinfo/pythondotnet
Roman Yakovenko
2006-04-03 17:17:30 UTC
Permalink
Post by Lalit DIGARI
Hello All ,
I have devloped a c++ dll named mydll in c++ how can I access it with in python script using ctype...
Hi. I think this is the wrong mailing list to ask. Any way, you can not do it.
There are 2 reasons:
1. functions name mangling
2. resource management

You have few choices:
1. To create thin wrapper to dll that will expose ".NET" interface
2. To use boost.python library ( or if you resist SWIG )
Post by Lalit DIGARI
Regard's
Lalit
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
_________________________________________________
Python.NET mailing list - PythonDotNet-+ZN9ApsXKcEdnm+***@public.gmane.org
http://mail.python.org/mailman/listinfo/pythondotnet
Lalit DIGARI
2006-04-04 04:36:52 UTC
Permalink
Thanks mark,
How could I use dll's exposed function with in python script?
Reagrd's
lalit

-----Original Message-----
From: Mark McMahon [mailto:mark.mcmahon-***@public.gmane.org]
Sent: Monday, April 03, 2006 5:41 PM
To: Lalit DIGARI; pythondotnet-+ZN9ApsXKcEdnm+***@public.gmane.org
Subject: RE: [Python.NET] Use of c++ dll in python


Hi Lalit,

This is not really the group to ask this question - as it doesn't have
anything to do with python.NET.

But other then that I can answer your question I think :-)

You say a "C++ DLL". First thing is you need to make sure that your
functions are correctly exported in an 'unmangled' form.

What I do for this is the following:

// create a macro DLLEXPORT for those methods you want to export
#define DLLEXPORT extern "C" __declspec(dllexport)

// the following may be optional - but can make things easier
#define VB __stdcall

// add the macro to your function prototypes
DLLEXPORT int VB InitDialogFromFile (char const *const fileName);

// in the CPP file define your function as you would normally do int VB
InitDialogFromFile(char const * const fileName) {
//FUNC BODY
}

You may also need to create a .def file

; Declares the module parameters for the DLL.
NAME MyCPPDll.dll
DESCRIPTION 'Description of your DLL'
EXPORTS
// the following line can be used to rename exports
//InitDialogFromFile_renamed = InitDialogFromFile
InitDialogFromFile

Once you add that to the project - it will make sure that no mangling
happens (sometimes even after doing extern "C" you still get a leading
underscore!)

Mark


-----Original Message-----
From: pythondotnet-bounces-+ZN9ApsXKcEdnm+***@public.gmane.org
[mailto:pythondotnet-bounces-+ZN9ApsXKcEdnm+***@public.gmane.org] On Behalf Of Lalit DIGARI
Sent: Monday, April 03, 2006 7:22 AM
To: pythondotnet-+ZN9ApsXKcEdnm+***@public.gmane.org
Subject: [Python.NET] Use of c++ dll in python

Hello All ,
I have devloped a c++ dll named mydll in c++ how can I access it with in
python script using ctype... Regard's Lalit

_________________________________________________
Python.NET mailing list - PythonDotNet-+ZN9ApsXKcEdnm+***@public.gmane.org
http://mail.python.org/mailman/listinfo/pythondotnet


_________________________________________________
Python.NET mailing list - PythonDotNet-+ZN9ApsXKcEdnm+***@public.gmane.org
http://mail.python.org/mailman/listinfo/pythondotnet
Brian Lloyd
2006-04-04 12:32:02 UTC
Permalink
Lalit,

If your C++ dll is a plain (unmanaged, machine-code) dll, you probably want to
take a look at ctypes:

http://starship.python.net/crew/theller/ctypes/

Python for .NET doesn't specifically help you use arbitrary unmanaged
dlls (but you
should have no problem using ctypes within Python for .NET).

-Brian
Post by Lalit DIGARI
Thanks mark,
How could I use dll's exposed function with in python script?
Reagrd's
lalit
-----Original Message-----
Sent: Monday, April 03, 2006 5:41 PM
Subject: RE: [Python.NET] Use of c++ dll in python
Hi Lalit,
This is not really the group to ask this question - as it doesn't have
anything to do with python.NET.
But other then that I can answer your question I think :-)
You say a "C++ DLL". First thing is you need to make sure that your
functions are correctly exported in an 'unmangled' form.
// create a macro DLLEXPORT for those methods you want to export
#define DLLEXPORT extern "C" __declspec(dllexport)
// the following may be optional - but can make things easier
#define VB __stdcall
// add the macro to your function prototypes
DLLEXPORT int VB InitDialogFromFile (char const *const fileName);
// in the CPP file define your function as you would normally do int VB
InitDialogFromFile(char const * const fileName) {
//FUNC BODY
}
You may also need to create a .def file
; Declares the module parameters for the DLL.
NAME MyCPPDll.dll
DESCRIPTION 'Description of your DLL'
EXPORTS
// the following line can be used to rename exports
//InitDialogFromFile_renamed = InitDialogFromFile
InitDialogFromFile
Once you add that to the project - it will make sure that no mangling
happens (sometimes even after doing extern "C" you still get a leading
underscore!)
Mark
-----Original Message-----
Sent: Monday, April 03, 2006 7:22 AM
Subject: [Python.NET] Use of c++ dll in python
Hello All ,
I have devloped a c++ dll named mydll in c++ how can I access it with in
python script using ctype... Regard's Lalit
_________________________________________________
http://mail.python.org/mailman/listinfo/pythondotnet
_________________________________________________
http://mail.python.org/mailman/listinfo/pythondotnet
_________________________________________________
Python.NET mailing list - PythonDotNet-+ZN9ApsXKcEdnm+***@public.gmane.org
http://mail.python.org/mailman/listinfo/pythondotnet
Mark McMahon
2006-04-03 12:11:23 UTC
Permalink
Hi Lalit,

This is not really the group to ask this question - as it doesn't have anything to do with python.NET.

But other then that I can answer your question I think :-)

You say a "C++ DLL". First thing is you need to make sure that your functions are correctly exported in an 'unmangled' form.

What I do for this is the following:

// create a macro DLLEXPORT for those methods you want to export
#define DLLEXPORT extern "C" __declspec(dllexport)

// the following may be optional - but can make things easier
#define VB __stdcall

// add the macro to your function prototypes
DLLEXPORT int VB InitDialogFromFile (char const *const fileName);

// in the CPP file define your function as you would normally do
int VB InitDialogFromFile(char const * const fileName)
{
//FUNC BODY
}

You may also need to create a .def file

; Declares the module parameters for the DLL.
NAME MyCPPDll.dll
DESCRIPTION 'Description of your DLL'
EXPORTS
// the following line can be used to rename exports
//InitDialogFromFile_renamed = InitDialogFromFile
InitDialogFromFile

Once you add that to the project - it will make sure that no mangling happens (sometimes even after doing extern "C" you still get a leading underscore!)

Mark


-----Original Message-----
From: pythondotnet-bounces-+ZN9ApsXKcEdnm+***@public.gmane.org [mailto:pythondotnet-bounces-+ZN9ApsXKcEdnm+***@public.gmane.org] On Behalf Of Lalit DIGARI
Sent: Monday, April 03, 2006 7:22 AM
To: pythondotnet-+ZN9ApsXKcEdnm+***@public.gmane.org
Subject: [Python.NET] Use of c++ dll in python

Hello All ,
I have devloped a c++ dll named mydll in c++ how can I access it with in python script using ctype...
Regard's
Lalit

_________________________________________________
Python.NET mailing list - PythonDotNet-+ZN9ApsXKcEdnm+***@public.gmane.org
http://mail.python.org/mailman/listinfo/pythondotnet

_________________________________________________
Python.NET mailing list - PythonDotNet-+ZN9ApsXKcEdnm+***@public.gmane.org
http://mail.python.org/mailman/listinfo/pythondotnet
Lalit DIGARI
2006-04-20 11:52:53 UTC
Permalink
Helllo guys,
Is there any pyhthon function as c's strcmp function

Regard's
Lalit
-----Original Message-----
From: Mark McMahon [mailto:mark.mcmahon-***@public.gmane.org]
Sent: Monday, April 03, 2006 5:41 PM
To: Lalit DIGARI; pythondotnet-+ZN9ApsXKcEdnm+***@public.gmane.org
Subject: RE: [Python.NET] Use of c++ dll in python


Hi Lalit,

This is not really the group to ask this question - as it doesn't have
anything to do with python.NET.

But other then that I can answer your question I think :-)

You say a "C++ DLL". First thing is you need to make sure that your
functions are correctly exported in an 'unmangled' form.

What I do for this is the following:

// create a macro DLLEXPORT for those methods you want to export
#define DLLEXPORT extern "C" __declspec(dllexport)

// the following may be optional - but can make things easier
#define VB __stdcall

// add the macro to your function prototypes
DLLEXPORT int VB InitDialogFromFile (char const *const fileName);

// in the CPP file define your function as you would normally do int VB
InitDialogFromFile(char const * const fileName) {
//FUNC BODY
}

You may also need to create a .def file

; Declares the module parameters for the DLL.
NAME MyCPPDll.dll
DESCRIPTION 'Description of your DLL'
EXPORTS
// the following line can be used to rename exports
//InitDialogFromFile_renamed = InitDialogFromFile
InitDialogFromFile

Once you add that to the project - it will make sure that no mangling
happens (sometimes even after doing extern "C" you still get a leading
underscore!)

Mark


-----Original Message-----
From: pythondotnet-bounces-+ZN9ApsXKcEdnm+***@public.gmane.org
[mailto:pythondotnet-bounces-+ZN9ApsXKcEdnm+***@public.gmane.org] On Behalf Of Lalit DIGARI
Sent: Monday, April 03, 2006 7:22 AM
To: pythondotnet-+ZN9ApsXKcEdnm+***@public.gmane.org
Subject: [Python.NET] Use of c++ dll in python

Hello All ,
I have devloped a c++ dll named mydll in c++ how can I access it with in
python script using ctype... Regard's Lalit

_________________________________________________
Python.NET mailing list - PythonDotNet-+ZN9ApsXKcEdnm+***@public.gmane.org
http://mail.python.org/mailman/listinfo/pythondotnet


_________________________________________________
Python.NET mailing list - PythonDotNet-+ZN9ApsXKcEdnm+***@public.gmane.org
http://mail.python.org/mailman/listinfo/pythondotnet

Mark McMahon
2006-04-04 11:55:35 UTC
Permalink
Hi Lalit,


import ctypes

(or maybe windll instead of cdll below)
ctypes.cdll.YourDllName.InitDialogFromFile("InitFromThisFile.txt")

Simple, no? :-)

For anything more complex - please look at the ctypes help.
Ctypes helps you a lot - but there is no substitute for reading the help or googling around the 'net for some examples.

Mark

-----Original Message-----
From: Lalit DIGARI [mailto:lalit.digari-***@public.gmane.org]
Sent: Tuesday, April 04, 2006 12:37 AM
To: Mark McMahon
Cc: pythondotnet-+ZN9ApsXKcEdnm+***@public.gmane.org
Subject: RE: [Python.NET] Use of c++ dll in python

Thanks mark,
How could I use dll's exposed function with in python script?
Reagrd's
lalit

-----Original Message-----
From: Mark McMahon [mailto:mark.mcmahon-***@public.gmane.org]
Sent: Monday, April 03, 2006 5:41 PM
To: Lalit DIGARI; pythondotnet-+ZN9ApsXKcEdnm+***@public.gmane.org
Subject: RE: [Python.NET] Use of c++ dll in python


Hi Lalit,

This is not really the group to ask this question - as it doesn't have
anything to do with python.NET.

But other then that I can answer your question I think :-)

You say a "C++ DLL". First thing is you need to make sure that your
functions are correctly exported in an 'unmangled' form.

What I do for this is the following:

// create a macro DLLEXPORT for those methods you want to export
#define DLLEXPORT extern "C" __declspec(dllexport)

// the following may be optional - but can make things easier
#define VB __stdcall

// add the macro to your function prototypes
DLLEXPORT int VB InitDialogFromFile (char const *const fileName);

// in the CPP file define your function as you would normally do int VB
InitDialogFromFile(char const * const fileName) {
//FUNC BODY
}

You may also need to create a .def file

; Declares the module parameters for the DLL.
NAME MyCPPDll.dll
DESCRIPTION 'Description of your DLL'
EXPORTS
// the following line can be used to rename exports
//InitDialogFromFile_renamed = InitDialogFromFile
InitDialogFromFile

Once you add that to the project - it will make sure that no mangling
happens (sometimes even after doing extern "C" you still get a leading
underscore!)

Mark


-----Original Message-----
From: pythondotnet-bounces-+ZN9ApsXKcEdnm+***@public.gmane.org
[mailto:pythondotnet-bounces-+ZN9ApsXKcEdnm+***@public.gmane.org] On Behalf Of Lalit DIGARI
Sent: Monday, April 03, 2006 7:22 AM
To: pythondotnet-+ZN9ApsXKcEdnm+***@public.gmane.org
Subject: [Python.NET] Use of c++ dll in python

Hello All ,
I have devloped a c++ dll named mydll in c++ how can I access it with in
python script using ctype... Regard's Lalit

_________________________________________________
Python.NET mailing list - PythonDotNet-+ZN9ApsXKcEdnm+***@public.gmane.org
http://mail.python.org/mailman/listinfo/pythondotnet



_________________________________________________
Python.NET mailing list - PythonDotNet-+ZN9ApsXKcEdnm+***@public.gmane.org
http://mail.python.org/mailman/listinfo/pythondotnet
Loading...