Please help in calling python fucntion from 'c'

Praveen Patil praveen.patil at
Wed Sep 4 08:36:16 EDT 2002


I have written 'C' dll(MY_DLL.DLL) . I am importing 'C' dll in python
I want to call python function from 'c' function.
For your reference I have attached 'c' and python files to this mail.
In my pc:
python code is under the directory D:\test\
dll is under the directory C:\Program Files\Python\DLLs\MY_DLL.pyd

Here are the steps I am following.

step(1): I am calling 'C' function(RECEIVE_FROM_IL_S) from python.
         This 'C' function is existing imported dll(MY_DLL).
step(2): I want to call python function(TestFunction) from 'C'

Python code is(  :-
import MY_DLL

G_Logfile          = None

def TestFunction():
    G_Logfile = open('Pytestfile.txt', 'w')
    G_Logfile.write("%s \n"%'I am writing python created text file')
    G_Logfile = None
#end def TestFunction

if __name__ == "__main__":


'C' code is (MY_DLL.c) :-
#include <windows.h>
#include <stdio.h>
#include <Python.h>

PyObject* _wrap_RECEIVE_FROM_IL_S(PyObject *self, PyObject *args)
    FILE* fp;
    PyObject* _resultobj;
    int i,j;

    if( !(PyArg_ParseTuple(args, "ii",&i,&j)))
       return NULL;
    fp= fopen("RECEIVE_IL_S.txt", "w");
    fprintf(fp, "i=%d   j=%d" , i,j);

    /* Here I want to call python function(TestFunction). Please suggest me
some solution*/

    _resultobj = Py_None;
    return _resultobj;

static PyMethodDef MY_DLL_methods[] = {
      { NULL , NULL}

__declspec(dllexport) void __cdecl initMY_DLL(void)

Please anybody help me solving the problem.


-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
URL: <>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: MY_DLL.c
Type: application/octet-stream
Size: 788 bytes
Desc: not available
URL: <>
-------------- next part --------------
[ The information contained in this e-mail is confidential and is intended for the named recipient only. If you are not the named recipient, please notify us by telephone on +44 (0)1249 442 430 immediately, destroy the message and delete it from your computer. Silver Software has taken every reasonable precaution to ensure that any attachment to this e-mail has been checked for viruses. However, we cannot accept liability for any damage sustained as a result of any such software viruses and advise you to carry out your own virus check before opening any attachment. Furthermore, we do not accept responsibility for any change made to this message after it was sent by the sender.]

More information about the Python-list mailing list