Python Forum
Calling a C Func though Pyhon Script using DLL file which is created for C file.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Calling a C Func though Pyhon Script using DLL file which is created for C file.
#1
1. I've created a C file (timestamp.c) having a function which returns the Timestamp in string format.
2. For this C file I've created a DLL (timestamp.dll) file which can call the above Function through Python Script.
for example::

from ctypes import *

libc = cdll.LoadLibrary("C:\\MinGW\\bin\\timestamp.dll")
print libc.GetMicroSecTimeStamp()


3. After running this script I'm getting an output like this :: 1734103168
4. But I'm expecting an Output like this :: 1483617487.419234 (This is an output from executable C file using the same function)
5. I don't know whether the Python output is right or wrong. I guess it's a wrong one.

My question is whether the my DLL file is linking properly or not?
Below are the things I've done to generate & link the DLL file.
--> gcc -c timestamp.c -o timestamp.o
--> gcc -c timestamp.dll -s -shared timestamp.o
--> gcc -c main.c -o main.o
--> gcc -o main.exe -s main.o -L. -ltimestamp

then I copied the DLL file into "bin" directory of my C Compiler.

Are there any mistakes in my steps in Linking the DLL properly ?
My target is to Get the timestamps whenever I calls libc.GetMicroSecTimeStamp().
For that how can I Link my DLL file at run time ? 
If any inputs needed please let me know.

Thanks in Advance.
Reply
#2
can you show the C source code?

can you wrap your call with repr like this:

print repr(libc.GetMicroSecTimeStamp())
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#3
Hi.

How do I get a python code to call a C code?
The reverse doesnt seem to be working as C doesnt support a few nescessary advanced libraries.
I am using WiringPI on the odroid c2 . I have a C code that uses the wiringP library and another python script that does something else. I want this python script to call the C code (functions) in a loop using CTYPES
Kindly help.

Thank you.
Reply
#4
Please use code tags
Hello, please read the following: https://python-forum.io/misc.php?action=help&hid=25
Thank you
Reply
#5
although i have done c (2000+) and have done a good bit of python (50+) so far, i have not yet learned how to call a linkable c function. i only know how to execvp() a program and pipe its output back to my python program. that's not what you are asking for.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  File is not being created with 'w' argument CAD79 3 422 Mar-14-2024, 12:05 PM
Last Post: snippsat
  python script is hanging while calling a procedure in database prasanthi417 4 503 Jan-17-2024, 02:33 PM
Last Post: deanhystad
  file open "file not found error" shanoger 8 1,087 Dec-14-2023, 08:03 AM
Last Post: shanoger
  Need to replace a string with a file (HTML file) tester_V 1 761 Aug-30-2023, 03:42 AM
Last Post: Larz60+
  How can I change the uuid name of a file to his original file? MaddoxMB 2 921 Jul-17-2023, 10:15 PM
Last Post: Pedroski55
  Calling a function (which accesses a library) from another file mouse9095 4 814 Jun-07-2023, 08:55 PM
Last Post: deanhystad
  Python Script to convert Json to CSV file chvsnarayana 8 2,496 Apr-26-2023, 10:31 PM
Last Post: DeaD_EyE
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,089 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,111 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  Script File Failure-Path Error? jerryf 13 3,450 Nov-30-2022, 09:58 AM
Last Post: jerryf

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020