Embedding Python in C DLL

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • terti

    #1

    Embedding Python in C DLL

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

    from NLRclient import NLRclient
    i = NLRclient("serv er")
    s = i.getStrSort("q werty")


    // 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_Import ModuleEx( "NLRclient" , Py_BuildValue(" "),
    Py_BuildValue(" ") , Py_BuildValue( "[s]", "NLRclient" ));

    // i = NLRclient("serv er")
    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("q werty")

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



    Py_Finalize();
    return 0;


    Many thanks,
    Tertius
  • terti

    #2
    Re: Embedding Python in C DLL

    The following site cleared things up for me.



    I changed my Python script to a module with functions rather than a
    class with methods. With no instantiation needed, things started working
    better.

    Regards,
    Tertius

    Comment

    Working...