Skip to content Skip to sidebar Skip to footer

Python Ctypes Dll Stdout

I am calling a DLL function from python using ctypes, and simply I want to capture the stdout from the dll call. There are a lot of printf's I would like to redirect without chang

Solution 1:

Looks like you'll need to make a wrapper. Try something like this:

char* CallSomeFunc(){
    ostrstream ostr;
    cout.rdbuf(ostr.rdbuf());
    SomeFunc();
    char* s = ostr.str();
    return s;
}

You will actually need to do something different with that string rather than returning it; I'll leave that part up to you. The string pointer becomes invalid as soon as it is returned, but you could do a fairly simple allocation as long as you deallocate the memory after it is returned.

Post a Comment for "Python Ctypes Dll Stdout"