1.dll 项目
// Dll1.cpp : 定义 DLL 应用程序的入口点。 // #include "stdafx.h" extern "C"_declspec(dllexport) void maopao(int *p,int count); void maopao(int *p,int count) { int temp=0; for(int i=1;i<count;i++) { for(int j=count-1;j>=i;j--) { if(p[j]>p[j-1]) { temp=p[j]; p[j]=p[j-1]; p[j-1]=temp; } } } }
2.调用项目.
拷贝 Dll1.dll到相应的目录下
#include<iostream> #include<Windows.h> #include<time.h> typedef int(*Dllfun)(int *,int); using namespace std; int main() { Dllfun maopao1; HINSTANCE hdll; hdll=LoadLibrary("Dll1.dll"); if(hdll==NULL) {FreeLibrary(hdll); } maopao1=(Dllfun)GetProcAddress(hdll,"maopao"); if(maopao1==NULL) {FreeLibrary(hdll); } int a[10]; srand(time(0)); for(int i=0;i<10;i++) a[i]=rand()%50; maopao1(a,10); for(int i=0;i<10;i++) cout<<a[i]<<endl; FreeLibrary(hdll); }