Interface with MFC write the background with a written C program is OK
C written by the program compiled into a DLL, the function used to make an export function, in C + + W/MFC program called
1,VC can compile C function dynamic Library;
2.simple dll writing example ( Take the simplest two-number addition function as an example ):
Create Project Win32 Dynamic-link Library.
Add header files and source files such as dll.h dll.cpp ,
In the header file:
#ifndef Dll_h
#define Dll_h
extern "C" int __declspec (dllexport) Add (int x, int y);
#endif
In the source file:
#include "dll.h"
int add (int x, int y)
{
return x + y;
}
3,DLLsimple invocation of:
#include <stdio.h>
#include <windows.h>
typedef int (*lpaddfun) (int, int); //macro definition function pointer type
int main (int argc, char *argv[])
{
HINSTANCE hDLL; Dll Handle
Lpaddfun Addfun; //function Pointers
hDLL = LoadLibrary (".. \\Debug\\dll.dll "); //This is your last project .DLLpath, of course you can directly putDLLCopy to current project, so write directlyhDLL = LoadLibrary ("Dll.dll");
if (hdll! = NULL)
{
Addfun = (lpaddfun) GetProcAddress (hDLL, "add");
if (addfun! = NULL)
{
int result = Addfun (2, 3);
printf ("%d", result);//mfcchange it intoAfxMessageBoxto test
}
FreeLibrary (hDLL); //don't forget to release when you're done.
}
return 0;
}
MFC calls C Dynamic library functions-----to be replenished