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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:22:23+00:00 2026-06-02T04:22:23+00:00

I created the MathFuncsDll.dll from MSDN DLL example and running the calling .cpp worked

  • 0

I created the MathFuncsDll.dll from MSDN DLL example and running the calling .cpp worked fine. Now, trying to load this in IPython with ctypes like

import ctypes
lib = ctypes.WinDLL('MathFuncsDll.dll')

being in the correct folder yields

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 28: ordinal not in range(128)

Similarly in Python shell this yields

WindowsError: [Error 193] %1 is not a valid Win32 application

What should I change? Hm, it might be Win 7 64bit vs. some 32bit dll or something right? I’ll check later when I’ve time again.

  • 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-06-02T04:22:25+00:00Added an answer on June 2, 2026 at 4:22 am

    ctypes doesn’t work with C++, which the MathFuncsDLL example is written in.

    Instead, write in C, or at least export a “C” interface:

    #ifdef __cplusplus
    extern "C" {
    #endif
    
    __declspec(dllexport) double Add(double a, double b)
    {
        return a + b;
    }
    
    #ifdef __cplusplus
    }
    #endif
    

    Also note that the calling convention defaults to __cdecl, so use CDLL instead of WinDLL (which uses __stdcall calling convention):

    >>> import ctypes
    >>> dll=ctypes.CDLL('server')
    >>> dll.Add.restype = ctypes.c_double
    >>> dll.Add.argtypes = [ctypes.c_double,ctypes.c_double]
    >>> dll.Add(1.5,2.7)
    4.2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a .dll and .lib from a project so that
Created .NET WCF service, tested it - works. Generated schemas from Data and service
Created an OpenGraph action and object. Trying to submit my action. When I click
I created an anchor like this: <a id=create /> and it works in IE
I created a web control, and it needs some data from its parent page.
created a singleview application with storyboard. Added three viewcontrollers apart from the one view
Created basic C++ DLL and exported names using Module Definition file (MyDLL.def). After compilation
Created a profile using content provider. After running it correctly, added 3 fields to
Created a new project from the Tab Bar Application template, how can I access
I created an Image with this code OpenFileDialog dlg = new OpenFileDialog(); dlg.FileName =

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.