[Ironpython-users] IronPython: Import DLL library

Markus Schaber m.schaber at codesys.com
Fri Mar 13 09:39:58 CET 2015


Hi,

Just some additional thoughts / gut feelings:

The COM interfacing which is based on the .NET COM support seems to work rock solid / very stable.

The ctypes interfacing seems somehow brittle on corner cases, and is not easy to use in case of complex data structures, C++ interfacing may be even impossible. I guess, in those cases, you should create a wrapper DLL using C++/CLI – you can check the SharpSVN project for a very nice example of how to create a nice, OO .NET interface around a complex C interface.


Best regards

Markus Schaber

CODESYS® a trademark of 3S-Smart Software Solutions GmbH

Inspiring Automation Solutions
________________________________
3S-Smart Software Solutions GmbH
Dipl.-Inf. Markus Schaber | Product Development Core Technology
Memminger Str. 151 | 87439 Kempten | Germany
Tel. +49-831-54031-979 | Fax +49-831-54031-50

E-Mail: m.schaber at codesys.com<mailto:m.schaber at codesys.com> | Web: codesys.com<http://www.codesys.com> | CODESYS store: store.codesys.com<http://store.codesys.com>
CODESYS forum: forum.codesys.com<http://forum.codesys.com>

Managing Directors: Dipl.Inf. Dieter Hess, Dipl.Inf. Manfred Werner | Trade register: Kempten HRB 6186 | Tax ID No.: DE 167014915
________________________________
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received
this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorised copying, disclosure
or distribution of the material in this e-mail is strictly forbidden.
Von: Ironpython-users [mailto:ironpython-users-bounces+m.schaber=codesys.com at python.org] Im Auftrag von Markus Schaber
Gesendet: Freitag, 13. März 2015 09:30
An: Hemanth M B; ironpython-users at python.org
Betreff: Re: [Ironpython-users] IronPython: Import DLL library

Hi, Herman,

Sorry, I did not use any of those two myself yet, just heard some success (and a few failure) stories of others.

http://ironpython.net/documentation/dotnet/ contains some explanations and sample code for COM.


For ctypes, which _should_ work the same as in cPython, there are lots of examples and tutorials on the net: http://python.net/crew/theller/ctypes/tutorial.html


In both cases, I guess you will need basic knowledge of COM or C calling conventions and memory layout to be successful.

Best regards

Markus Schaber

CODESYS® a trademark of 3S-Smart Software Solutions GmbH

Inspiring Automation Solutions
________________________________
3S-Smart Software Solutions GmbH
Dipl.-Inf. Markus Schaber | Product Development Core Technology
Memminger Str. 151 | 87439 Kempten | Germany
Tel. +49-831-54031-979 | Fax +49-831-54031-50

E-Mail: m.schaber at codesys.com<mailto:m.schaber at codesys.com> | Web: codesys.com<http://www.codesys.com> | CODESYS store: store.codesys.com<http://store.codesys.com>
CODESYS forum: forum.codesys.com<http://forum.codesys.com>

Managing Directors: Dipl.Inf. Dieter Hess, Dipl.Inf. Manfred Werner | Trade register: Kempten HRB 6186 | Tax ID No.: DE 167014915
________________________________
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received
this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorised copying, disclosure
or distribution of the material in this e-mail is strictly forbidden.
Von: Hemanth M B [mailto:hemanth at broadcom.com]
Gesendet: Freitag, 13. März 2015 08:30
An: Markus Schaber; ironpython-users at python.org<mailto:ironpython-users at python.org>
Betreff: RE: [Ironpython-users] IronPython: Import DLL library

Thanks for info markus,

Can you please send me sample code to use ctypes and also COM interface?


Thanks and Regards,
Hemanth M B
@9010054054

From: Markus Schaber [mailto:m.schaber at codesys.com]
Sent: Friday, March 13, 2015 12:57 PM
To: Hemanth M B; ironpython-users at python.org<mailto:ironpython-users at python.org>
Subject: AW: [Ironpython-users] IronPython: Import DLL library

Hi,

I fit is not explicitly stated that it is C++/CLI (or some other keywords like “mixed mode” or “managed C++), I’d guess that it is pure native.

The library might expose a COM interface, in that case you could interact with it using COM.

Another way for a wrapper could be using the ctypes module from the standard library.

Best regards

Markus Schaber

CODESYS® a trademark of 3S-Smart Software Solutions GmbH

Inspiring Automation Solutions
________________________________
3S-Smart Software Solutions GmbH
Dipl.-Inf. Markus Schaber | Product Development Core Technology
Memminger Str. 151 | 87439 Kempten | Germany
Tel. +49-831-54031-979 | Fax +49-831-54031-50

E-Mail: m.schaber at codesys.com<mailto:m.schaber at codesys.com> | Web: codesys.com<http://www.codesys.com> | CODESYS store: store.codesys.com<http://store.codesys.com>
CODESYS forum: forum.codesys.com<http://forum.codesys.com>

Managing Directors: Dipl.Inf. Dieter Hess, Dipl.Inf. Manfred Werner | Trade register: Kempten HRB 6186 | Tax ID No.: DE 167014915
________________________________
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received
this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorised copying, disclosure
or distribution of the material in this e-mail is strictly forbidden.
Von: Ironpython-users [mailto:ironpython-users-bounces+m.schaber=codesys.com at python.org] Im Auftrag von Slide
Gesendet: Donnerstag, 12. März 2015 13:38
An: Hemanth M B; ironpython-users at python.org<mailto:ironpython-users at python.org>
Betreff: Re: [Ironpython-users] IronPython: Import DLL library

Where did you get the library? If it is native, then you would have to write a wrapper library in C# or CLI/C++ that interacted with the library through P/Invoke (for C#) or the native function calls if CLI/C++.

On Thu, Mar 12, 2015 at 5:14 AM Hemanth M B <hemanth at broadcom.com<mailto:hemanth at broadcom.com>> wrote:

Hi,

Thanks for your reply.

How to check the library is native C++ or not?

If it is a native C++ then, is there any work around for the same.

Thanks and Regards,
Hemanth M B
@9010054054

From: Slide [mailto:slide.o.mix at gmail.com<mailto:slide.o.mix at gmail.com>]
Sent: Thursday, March 12, 2015 5:35 PM
To: Hemanth M B; ironpython-users at python.org<mailto:ironpython-users at python.org>
Subject: Re: [Ironpython-users] IronPython: Import DLL library

Do you mean the library is CLI/C++, or is it native C++? If native C++, it won't work with IronPython currently.

On Thu, Mar 12, 2015 at 4:11 AM Hemanth M B <hemanth at broadcom.com<mailto:hemanth at broadcom.com>> wrote:
HI All,


I am trying to add reference and import BMAPIa.DLL library using CLR. But it is throwing an error message.

My code:

Import clr
Clr.AddReferenceToFile(“BMAPIa.dll”)
Import BMAPIa

Error:

C:\Users\Administrator>"C:\Program Files (x86)\IronPython 2.7\ipy.exe" "C:\Users\Administrator\Desktop\AMD64\test.py"
Traceback (most recent call last):
  File "C:\Users\Administrator\Desktop\AMD64\test.py", line 9, in <module>
SystemError: The module was expected to contain an assembly manifest. (Exception from HRESULT: 0x80131018)

Please let me know where am i going wrong?

FYI…. This is library is written in C++ and I am not aware of in which .NET framework it is been built.




Thanks and Regards,
Hemanth M B
@9010054054

_______________________________________________
Ironpython-users mailing list
Ironpython-users at python.org<mailto:Ironpython-users at python.org>
https://mail.python.org/mailman/listinfo/ironpython-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20150313/57d55125/attachment.html>


More information about the Ironpython-users mailing list