c++ – Calling C ++ dll from python: builtins.OSError: [WinError 126] The specified module could not be found


I am trying to call C ++ dll from python. Throws an error like this:

File "C:\Python34\Lib\ctypes\__init__.py", line 351, in __init__
    self._handle = _dlopen(self._name, mode)
builtins.OSError: [WinError 126] Не найден указанный модуль

Tell me what to do

#include "stdafx.h"
#include "wrap1.h"
#include <stdexcept>

using namespace std;

namespace MathFuncs
        double MyMathFuncs::Multiply(double a, double b)
        return a * b;

extern "C" {
    double MathFuncs_Multiply(double a, double b) {
        return MathFuncs::MyMathFuncs::Multiply(a, b);

And a call from python

from ctypes import CDLL, c_double

lib = CDLL("wrap1.dll")
func = lib.MathFuncs_Multiply
func.restype = c_double

res = func(c_double(2.0), c_double(3.2))


The .dll being called is in a directory different from where the .py is, and that directory is not listed in the PATH.
Check it like this:

>>> import ctypes
>>> ctypes.windll.LoadLibrary("wrap1.dll")

or with an indication of the path (forward slashes !!!):

>>> ctypes.windll.LoadLibrary("c:/path/wrap1.dll")
Scroll to Top