By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,441 Members | 998 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,441 IT Pros & Developers. It's quick & easy.

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

P: 1
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(dllexport) int add_int(int num1, int num2)
return num1+num2;


__declspec(dllexport) 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(dllexport) void printFunc()
printf("hello world !!");

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

mydll = cdll.LoadLibrary('path\\to\\sharedLibrary.dll')

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

I would like to know any inputs on this :)
Nov 7 '17 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.