Embedding Python in C DLL

terti terti at mighty.co.za
Wed Sep 8 13:24:52 EDT 2004


Hi,
// I need some help to embed the equivalent of the following Python code 
in a C DLL.

      from NLRclient import NLRclient
      i = NLRclient("server")
      s = i.getStrSort("qwerty")


// This what I have so far:

     PyObject *module, *i;
     PyObject *arg , *kw;

// The following I will put in the DllMain entrypoint
     Py_Initialize();

// from NLRclient import NLRclient
     module = PyImport_ImportModuleEx( "NLRclient", Py_BuildValue(""), 
Py_BuildValue("")   , Py_BuildValue( "[s]", "NLRclient" ));

// i = NLRclient("server")
     i = PyInstance_New( module, Py_BuildValue("s","server"), 
Py_BuildValue(""));


Up to here the program compiles but when I run the application, I get a 
runtime error dialog.





//This will be placed in one of the Dll functions
//    s = i.getStrSort("qwerty")

How to I invoke a method from the created "i" instance  ?



      Py_Finalize();
      return 0;


Many thanks,
Tertius



More information about the Python-list mailing list