SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

call python dll from C++

Last post 03-13-2017 7:29 PM by GTom001. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 02-05-2017 5:03 AM

    call python dll from C++

    To Whom It May Concern:

         I would like to call a Python dll in C++. I am using SharpDevelop 4.4.

       An example source file for Python would be:

        def somemethod(self):

            print "in some method"

        def isodd(self, n):
            return 1 == n % 2

      How would I:

      1) import the dll: + write function prototypes

      2) specify the parameters in c format:

          Python list, string, int, float, double, bool

      3) pass ByVal or ByRef in c 

        Thank you,

                   Tom

  • 03-13-2017 7:29 PM In reply to

    Re: call python dll from C++

    Hello Everyone:

       Here is what I have for the c++ code:

       #include <windows.h>

       #include <stdio.h>

       #include <conio.h>

       #include <iostream>

       typedef void (*Myfun)(void);

        /*extern "C"

        {

         __declspec(dllexport) void Myfun(void);

        };*/

        int main(int argc, char* argv[) {

    HINSTANCE LoadMe;

    LoadMe = LoadLibrary("C:\\MYDLL\\dll002.dll");

    if (LoadMe != 0)

        printf("LoadMe library loaded! ");

    else

        printf("LoadMe library failed to load! ");

        Myfun LibMainEntryPoint;

        LibMainEntryPoint = (Myfun)GetProcAddress(LoadMe,/*"entryPoint"*/"Myfun");

    if(LibMainEntryPoint == NULL)

    printf("Failed to get address of Func");

    printf("Error: %d", GetLastError());

    //Call Function Fails???

    //LibMainEntryPoint();

    system("pause");

    return 0;

        }

        And here is what I have for the python code:

        def Myfun():

    print "hello"

        #End of Code

        Does anyone have any ideas? I am not sure how to

        export the function in python code. I am not sure

        the function is in the dll. GetLastError() returns

        127. Online it says the specified procedure could

          not be found. Any help would be appreciated.

        Thank you,

                   Tom

Page 1 of 1 (2 items)
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.