printf() within a C-function outputs wrong result in Python when using ctypes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • egavandit
    New Member
    • Nov 2017
    • 1

    printf() within a C-function outputs wrong result in Python when using ctypes

    Hello all,

    I have the following problem. Any help would be appreciated :)

    I am trying to call a C function from Python using ctypes. I have been successful already in sharing the shared library (.dll on Windows with MS Visual Studio 2017) to Python 3.6.3.

    Also, simple functions like

    __declspec(dlle xport) int add_int(int num1, int num2)
    {
    return num1+num2;
    }

    and

    __declspec(dlle xport) float add_float(float num1, float num2)
    {
    float num3 = num1 + num2;
    return num3;
    }

    has provided me with correct result. But there is a problem when I try to call the following function:

    __declspec(dlle xport) void printFunc()
    {
    printf("hello world !!");
    }

    I would like to see the output at Python interpreter as 'hello world !!' when I execute

    mydll = cdll.LoadLibrar y('path\\to\\sh aredLibrary.dll ')
    mydll.printFunc ()

    Currently I see the output as an integer when I execute the above code.

    I would like to know any inputs on this :)
Working...