Python and DLL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lskov
    New Member
    • Apr 2007
    • 14

    #1

    Python and DLL

    Hey

    I have a dllfile "WtcProvider.dl l" and now i will try to import it in python. So i can use the functions in it.

    After a fast research on google it looks like it is possible. But i cant find a way so how to got it to work.

    Anyone there can helt me with loadina an dll file?
  • dshimer
    Recognized Expert New Member
    • Dec 2006
    • 136

    #2
    First let me admit I know almost nothing about this and it's been a while since I wrote and used the following code snippet. It is not complete but gives an example of a few lines which do what you want. It uses the dll from the corpscon coordinate reprojection library which for which the documentation is quite easy to find on the web. My hope is that if you looked at a combination of the ctypes documentation, the corpscon dll documentation, and the following snippet, you might gather some useful information. It is amazing how much power you can add to a program using DLL's and didn't seem that bad once I got the hang of it.
    Code:
    from ctypes import *
    
    corpslib = windll.LoadLibrary("C:\Program Files\Corpscon6\corpscon_v6.dll")
    tmpStr = create_string_buffer(256) 
    corpslib.corpscon_default_config ()
    corpslib.corpscon_initialize_convert()
    stat = corpslib.SetNadconPath(r"C:\Program Files\Corpscon6\Nadcon")
    stat = corpslib.SetVertconPath(r"C:\Program Files\Corpscon6\Vertcon")
    stat = corpslib.SetGeoidPath(r"C:\Program Files\Corpscon6\Geoid")
    stat = corpslib.SetInSystem(3)
    stat = corpslib.SetInDatum(InDatum)
    stat = corpslib.SetOutSystem(2)
    stat = corpslib.SetOutDatum(OutDatum)
    stat = corpslib.SetInUnits(3)
    stat = corpslib.SetOutUnits(OutUnits)
    stat = corpslib.SetInZone(UTMZone)
    stat = corpslib.SetOutZone(OutZone)
    inDatum = corpslib.GetInDatum()
    outDatum = corpslib.GetOutDatum()
    inSystem = corpslib.GetInSystem()
    outSystem = corpslib.GetOutSystem()
    inUnits = corpslib.GetInUnits()
    outUnits = corpslib.GetOutUnits()
    inZone = corpslib.GetInZone()
    outZone = corpslib.GetOutZone()
    I also remember something about having to pass in c double pointers which was accomplished in the following code.
    Code:
    inx = c_double(StartX)
    iny = c_double(StartY+(value*GridSize))
    inz = c_double(0.00)
    outx = c_double()
    outy = c_double()
    outz = c_double()
    corpslib.SetXIn(inx)
    corpslib.SetYIn(iny)
    corpslib.SetZIn(inz)
    corpslib.corpscon_convert()
    corpslib.GetXOut.restype = c_double
    corpslib.GetYOut.restype = c_double
    corpslib.GetZOut.restype = c_double
    PtX = corpslib.GetXOut()
    PtY = corpslib.GetYOut()

    Comment

    • lskov
      New Member
      • Apr 2007
      • 14

      #3
      thanks i will look on it an hope i got it to work

      Comment

      • bartonc
        Recognized Expert Expert
        • Sep 2006
        • 6478

        #4
        Originally posted by lskov
        Hey

        I have a dllfile "WtcProvider.dl l" and now i will try to import it in python. So i can use the functions in it.

        After a fast research on google it looks like it is possible. But i cant find a way so how to got it to work.

        Anyone there can helt me with loadina an dll file?
        I've gotten lots of experience with the ctypes module (included in version 2.5, downloadable for 2.4) lately. Being able to call dll functions is a VERY cool addition to the power of Python. The documentaion is in the 2.5 help file or on-line at http://docs.python.org/dev/lib/module-ctypes.html

        Comment

        Working...