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?

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.