C語言函式封裝例子
func1(.....)
{
.....
.....
}
func2(......)
{
.....
.....
}
func3(.....)
{
func1(....)
{
func2(...)
{
}
}
能不能將func1和func2封裝成一個DLL,能夠直接讓func3調用?
當然可以,寫一個DLL就可以了,把fun1和fun2寫進去,舉個例子:在DLL中寫入://MyDll.h extern "C" _declspec(dllexport) int Max(int a, int b); //MyDll.cpp#include "windows.h"#include "MyDll.h"int Max(int a, int b) { if(a>=b)return a; else return b; } 在console應用程式中寫入:#include "stdio.h" #include "stdlib.h" extern "C" _declspec(dllexport) int Max(int a, int b); #pragma comment(lib,"MyDll.lib") int main() { int a; a = Max(10, 5); printf("%d \n", a); return 0; }