1

I have exported this simple function from an DLL (Am working in MSVC2015, Windows 10, x64) :

// Main.h
#define DLL_SEMANTICS __declspec (dllexport)
extern "C"
{
    DLL_SEMANTICS int CheckVal(const int x, const int y = 1);

}

code:

// Main.cpp

    int CheckVal(const int x, const int y)
    { cout << y << endl; return 0; }

}

According to this SO thread using extern "C" shouldn't be a problem and indeed when calling this function from an exe file I got the desired results (i.e., "1" to the console) but but when I called this from Python using:

import ctypes
from ctypes import cdll

dllPath = r"C:\MyDll.dll"
lib = cdll.LoadLibrary(dllPath)
lib.CheckVal(ctypes.c_int(1))

I am getting some garbage value being printed (Debugging via PTVS confirmed that y is indeed garbage value.)

Am I doing something wrong or defualt parameters cannot work from Python?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Benny K
  • 1,957
  • 18
  • 33

1 Answers1

1

Default parameters are a nicety of C++. You need to pass two arguments if you're calling outside C++.

Botje
  • 26,269
  • 3
  • 31
  • 41