0

As the title, is there some way to import c *.lib in python (or Ironpython) directly without any wrapping? (such as *.dll including wrapping functions)

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
shihuan83
  • 15
  • 6
  • 1
    Have you done any research into this yourself yet? Have you seen the [`ctypes` module](http://docs.python.org/2/library/ctypes.html) (in the Python standard library)? – Martijn Pieters Oct 28 '13 at 07:25
  • This is not how Stack Overflow questions work; it is not a forum conversation. Don't change the question after you get an answer, post a **new** question instead. – Martijn Pieters Oct 28 '13 at 08:08
  • OK. I am sorry I didn't know. – shihuan83 Oct 28 '13 at 08:25

1 Answers1

1

Both CPython and IronPython come with the ctypes module, which lets you load DLLs directly:

from ctypes import *

print hex(windll.kernel32.GetModuleHandleA(None))

Do read the module documentation carefully, it includes a tutorial on how to pass in various C types correctly.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • And, after following the tutorial, you haven't been able to figure out how to call the `Init` function? – Martijn Pieters Oct 28 '13 at 08:02
  • Thank you for your reply. I have already got errors by executing windll.LoadLibrary. The Init function could obviously only be called after import the .dll successfully. – shihuan83 Oct 28 '13 at 08:13
  • According to the documentation `LoadLibrary()` only accepts DLL **names**, not filepaths. You need to make sure that the DLL can be found by Windows first, see http://msdn.microsoft.com/en-us/library/ms682586(v=vs.85).ASPX – Martijn Pieters Oct 28 '13 at 08:15
  • Thank you. I used LoadLibrary() with filepaths which worked. But for this case, whether filepath nor name works. – shihuan83 Oct 28 '13 at 08:24
  • And the DLL can be loaded in other programs? This does not look like a Python problem to me. – Martijn Pieters Oct 28 '13 at 08:27
  • Thank you. It can be loaded in other programs which are in c++. – shihuan83 Oct 28 '13 at 23:45