C++ generates DLLS using python to call DLL methods

  • 2020-04-02 13:22:29
  • OfStack

The first step is to set up a CPP DLL project, and then write the following code to generate the DLL


#include <stdio.h>     

#define DLLEXPORT extern "C" __declspec(dllexport)     

DLLEXPORT int __stdcall hello()     
{     
    printf("Hello world!n");     
    return 0;     
} 

Step 2: write a python file:


# coding: utf-8     

import os     
import ctypes     

CUR_PATH = os.path.dirname(__file__)     

if __name__ == '__main__':     
    print 'starting...'    
    dll = ctypes.WinDLL(os.path.join(CUR_PATH, 'hello.dll'))     
    dll.hello()


Related articles: