Generate DLL files and Python calls to functions in DLLs (parameter types and return values) __ function

Source: Internet
Author: User

Tools: VS2010 python2.7 (if you are using Python with 64-bit, the generated DLL also uses x64)

System: Win7pro 64bit


first, the creation of DLL projects and the generation of DLL files:

New Project-->win32 Project-->next-->dll,empty Project-->finish

If you do not select Empty project, several files are created automatically. Where Dllmain.cpp is the entry point for the DLL application.

Add head files (mydll.h), add source files (mydll.cpp)

In the header file:

#ifndef Lib_h
#define Lib_h
extern "C" {_declspec (dllexport) int Add (int* x, int y);
#endif

In the Mydll.cpp:

#include "mydll.h"
int Add (int* x, int y)
{
int a = (*x);
a++;

(*x) = A;
return y;
}

Ctrl+f7 after compiling no problem, on Build-->build Mydll, generated mydll.lib and MyDLL.DLL.

/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/

Tips

Debug: Debug version, contains debugging information, does not do any optimization, easy programmer to debug the program.

Release: Released version, in the amount of code and running speed are optimized to make the program run faster, easy to use users. )

/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/

Python calls to functions inside a DLL.

For an int with a intx pointer type, you want to handle the parameters in:

Import cTYPES
Dlltest = ctypes.cdll.LoadLibrary (' Dlltest.dll ')
A = Ctypes.c_int (5)
Print Dlltest.add (Ctypes.byref (a), 4)
Print A.value





















Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.