| | |
Calling c function from python
![]() |
•
•
Join Date: Oct 2005
Posts: 1
Reputation:
Solved Threads: 0
Hi all,
I am a newbie to python and am not sure,what i am doing is correct or not ,i wanna call c function from within python.
i have my python program as:
here RECEIVE_FROM_IL_S() is c function which i wanna call.And my c
function would be,
Also, if i don't want to pass any args to RECEIVE_FROM_IL_S from python what shud i do.
Regards,
john
Edit: Code tags added by vegaseat
I am a newbie to python and am not sure,what i am doing is correct or not ,i wanna call c function from within python.
i have my python program as:
Python Syntax (Toggle Plain Text)
import DLL if __name__ == "__main__": for i in range(1,6): DLL.RECEIVE_FROM_IL_S(10,50)
function would be,
#include <stdio.h>
#include <windows.h>
#include <stdio.h>
#ifdef _DEBUG
#undef _DEBUG
#include "python.h"
#define _DEBUG
#else
#include "python.h"
#endif
PyObject* _wrap_RECEIVE_FROM_IL_S(PyObject *self, PyObject *args)
{
FILE* fp;
PyObject* _resultobj;
int i,j;
if( !(PyArg_ParseTuple(args, "i",&i,&j)))
{
return NULL;
}
/*Here if i want to call another c function say SEND_TO_IL(),what shud i be including*/
fp= fopen('fileName.txt', "w");
fprintf(fp, "i=%d j=%d" , i,j);
fclose(fp);
_resultobj = Py_None;
return _resultobj;
}
static PyMethodDef MY_DLL_methods[] = {
{ "RECEIVE_FROM_IL_S", _wrap_RECEIVE_FROM_IL_S, METH_VARARGS },
{ "FUNC_CALL" , function,METH_VARARGS },
{ NULL , NULL}
};
__declspec(dllexport) void __cdecl initDLL(void)
{
Py_InitModule("DLL",MY_DLL_methods);
}Also, if i don't want to pass any args to RECEIVE_FROM_IL_S from python what shud i do.
Regards,
john
Edit: Code tags added by vegaseat
Are you following an example from a book?
Normally I would use the ctypes module from: http://starship.python.net/crew/theller/ctypes/
Normally I would use the ctypes module from: http://starship.python.net/crew/theller/ctypes/
May 'the Google' be with you!
![]() |
Similar Threads
- Helping with calling a function (C)
- python extending with c(doubts) (Python)
- Calling C function from MATLAB (C)
- Closure in Python (Python)
- Moving to Python From PHP: Using a variable in a function (Python)
- Still need info on calling a function from bool! (C++)
- How would i recode as a function? (Java)
- Function that returns void (C++)
Other Threads in the Python Forum
- Previous Thread: Python Graphics Help
- Next Thread: Segmentation fault
| Thread Tools | Search this Thread |
accessdenied advanced aliased anydbm app argv beginner bits calling casino cipher clear command conversion convert coordinates corners count csv cturtle cursor curves def definedlines development dynamic event events excel feet file float format frange function google handling homework i/o iframe input jaunty keyboard keycontrol lapse line linux list lists loan loop matching microphone mouse newb number numbers obexftp output parsing path prime programming projects py py2exe pygame pymailer pyopengl python random rational raw_input recursion recursive return searchingfile signal string strings tails text time tlapse tooltip tuple type ubuntu unicode url urllib urllib2 valueerror variable voip web-scrape whileloop word wxpython xlwt






