473,320 Members | 2,177 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Python and DLL

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
3 3002
dshimer
136 Expert 100+
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
lskov
14
thanks i will look on it an hope i got it to work
May 2 '07 #3
bartonc
6,596 Expert 4TB
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

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

Similar topics

0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.