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 6783455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:51:58+00:00 2026-05-26T16:51:58+00:00

I want to test wrapping a dll with ctypes . I’ve written the following

  • 0

I want to test wrapping a dll with ctypes. I’ve written the following test code and compiled it using Code::Blocks and Cygwin to a dll.

#define DLL_EXPORT extern "C" __declspec(dllexport)

DLL_EXPORT int sum(int a, int b) {
    return a + b;
}

Note: This is the whole code. Maybe there is something missing ?

Now, I copy the TestDll.dll to my Desktop and start the Python interpreter. But when I want to load it, the interpreter just exits !

C:\Users\niklas\Desktop>python
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win 32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
>>> dll = ctypes.WinDLL('TestDll')

C:\Users\niklas\Desktop>

However, loading any other library works, or giving an error if the library could not be found.
Can you tell me what I’m doing wrong here ?

Using Cygwin g++ 3.4.4

  • 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. Editorial Team
    Editorial Team
    2026-05-26T16:51:59+00:00Added an answer on May 26, 2026 at 4:51 pm

    Check objdump -p TestDll.dll | grep dll to see if you’ve linked in “cygwin1.dll” and nm TestDll.dll | grep Dll to see if you have a DllMain. The following command should build the DLL correctly:

    g++ testdll.c -mno-cygwin -shared -o TestDll.dll
    

    Also, you need to use CDLL for the cdecl calling convention, not WinDLL:

    >>> import ctypes
    >>> dll = ctypes.CDLL('TestDll')
    >>> dll.sum(4, 5)
    9
    

    Edit: I compiled with i686-w64-mingw32-g++.exe (4.5.3) from the Cygwin repository, but I used to use the default Cygwin gcc without a problem, given the -mno-cygwin option.

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

Sidebar

Related Questions

I want to test my part of code that returns the users password question.
I want to test the behavior of a certain piece of .NET code in
I have a bunch of repository classes which I want to unit-test using Visual
I want test a FIX gateway for our company and was wondering if anything
I want to test whether a certain string is contained in a short list
I want to test my app for my app launched with a URL scheme
I want to test the REST api on my Rails site. What is the
I want to test a Ajax based web application. I want to write the
I want to test whether two languages have a string in common. Both of
I want to test my application (especially SQL statements) against different databases. Actually I'm

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.