By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,235 Members | 1,008 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,235 IT Pros & Developers. It's quick & easy.

Python and DLL

P: 14
Hey

I have a dllfile "WtcProvider.dll" 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?
May 2 '07 #1
Share this Question
Share on Google+
3 Replies


dshimer
Expert 100+
P: 136
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.
Expand|Select|Wrap|Line Numbers
  1. from ctypes import *
  2.  
  3. corpslib = windll.LoadLibrary("C:\Program Files\Corpscon6\corpscon_v6.dll")
  4. tmpStr = create_string_buffer(256) 
  5. corpslib.corpscon_default_config ()
  6. corpslib.corpscon_initialize_convert()
  7. stat = corpslib.SetNadconPath(r"C:\Program Files\Corpscon6\Nadcon")
  8. stat = corpslib.SetVertconPath(r"C:\Program Files\Corpscon6\Vertcon")
  9. stat = corpslib.SetGeoidPath(r"C:\Program Files\Corpscon6\Geoid")
  10. stat = corpslib.SetInSystem(3)
  11. stat = corpslib.SetInDatum(InDatum)
  12. stat = corpslib.SetOutSystem(2)
  13. stat = corpslib.SetOutDatum(OutDatum)
  14. stat = corpslib.SetInUnits(3)
  15. stat = corpslib.SetOutUnits(OutUnits)
  16. stat = corpslib.SetInZone(UTMZone)
  17. stat = corpslib.SetOutZone(OutZone)
  18. inDatum = corpslib.GetInDatum()
  19. outDatum = corpslib.GetOutDatum()
  20. inSystem = corpslib.GetInSystem()
  21. outSystem = corpslib.GetOutSystem()
  22. inUnits = corpslib.GetInUnits()
  23. outUnits = corpslib.GetOutUnits()
  24. inZone = corpslib.GetInZone()
  25. outZone = corpslib.GetOutZone()
  26.  
I also remember something about having to pass in c double pointers which was accomplished in the following code.
Expand|Select|Wrap|Line Numbers
  1. inx = c_double(StartX)
  2. iny = c_double(StartY+(value*GridSize))
  3. inz = c_double(0.00)
  4. outx = c_double()
  5. outy = c_double()
  6. outz = c_double()
  7. corpslib.SetXIn(inx)
  8. corpslib.SetYIn(iny)
  9. corpslib.SetZIn(inz)
  10. corpslib.corpscon_convert()
  11. corpslib.GetXOut.restype = c_double
  12. corpslib.GetYOut.restype = c_double
  13. corpslib.GetZOut.restype = c_double
  14. PtX = corpslib.GetXOut()
  15. PtY = corpslib.GetYOut()
  16.  
May 2 '07 #2

P: 14
thanks i will look on it an hope i got it to work
May 2 '07 #3

bartonc
Expert 5K+
P: 6,596
Hey

I have a dllfile "WtcProvider.dll" 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
May 2 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.