Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 63129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:35:03+00:00 2026-05-10T18:35:03+00:00

What is the easiest way to use a DLL file from within Python ?

  • 0

What is the easiest way to use a DLL file from within Python?

Specifically, how can this be done without writing any additional wrapper C++ code to expose the functionality to Python?

Native Python functionality is strongly preferred over using a third-party library.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T18:35:04+00:00Added an answer on May 10, 2026 at 6:35 pm

    For ease of use, ctypes is the way to go.

    The following example of ctypes is from actual code I’ve written (in Python 2.5). This has been, by far, the easiest way I’ve found for doing what you ask.

    import ctypes  # Load DLL into memory.  hllDll = ctypes.WinDLL ('c:\\PComm\\ehlapi32.dll')  # Set up prototype and parameters for the desired function call. # HLLAPI  hllApiProto = ctypes.WINFUNCTYPE (     ctypes.c_int,      # Return type.     ctypes.c_void_p,   # Parameters 1 ...     ctypes.c_void_p,     ctypes.c_void_p,     ctypes.c_void_p)   # ... thru 4. hllApiParams = (1, 'p1', 0), (1, 'p2', 0), (1, 'p3',0), (1, 'p4',0),  # Actually map the call ('HLLAPI(...)') to a Python name.  hllApi = hllApiProto (('HLLAPI', hllDll), hllApiParams)  # This is how you can actually call the DLL function. # Set up the variables and call the Python name with them.  p1 = ctypes.c_int (1) p2 = ctypes.c_char_p (sessionVar) p3 = ctypes.c_int (1) p4 = ctypes.c_int (0) hllApi (ctypes.byref (p1), p2, ctypes.byref (p3), ctypes.byref (p4)) 

    The ctypes stuff has all the C-type data types (int, char, short, void*, and so on) and can pass by value or reference. It can also return specific data types although my example doesn’t do that (the HLL API returns values by modifying a variable passed by reference).


    In terms of the specific example shown above, IBM’s EHLLAPI is a fairly consistent interface.

    All calls pass four void pointers (EHLLAPI sends the return code back through the fourth parameter, a pointer to an int so, while I specify int as the return type, I can safely ignore it) as per IBM’s documentation here. In other words, the C variant of the function would be:

    int hllApi (void *p1, void *p2, void *p3, void *p4) 

    This makes for a single, simple ctypes function able to do anything the EHLLAPI library provides, but it’s likely that other libraries will need a separate ctypes function set up per library function.

    The return value from WINFUNCTYPE is a function prototype but you still have to set up more parameter information (over and above the types). Each tuple in hllApiParams has a parameter ‘direction’ (1 = input, 2 = output and so on), a parameter name and a default value – see the ctypes doco for details

    Once you have the prototype and parameter information, you can create a Python ‘callable’ hllApi with which to call the function. You simply create the needed variable (p1 through p4 in my case) and call the function with them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 175k
  • Answers 175k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer A structure in C++ is a class whose members are… May 12, 2026 at 3:07 pm
  • Editorial Team
    Editorial Team added an answer It's known as a ternary (because it has three operands)… May 12, 2026 at 3:07 pm
  • Editorial Team
    Editorial Team added an answer I assume you are trying to make cartoon style edges… May 12, 2026 at 3:07 pm

Related Questions

I have an old PowerBuilder application that we are slowly phasing out. We are
If I were to want to create a nice looking widget to stay running
What is the easiest way to use a valueconverter with a listbox? I'm setting
Basically, I have a jar file that i want to unzip to a specific

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.