C++ exe调用dll文件

生成dll程序

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;
   }
  }
 }
}

调用dll文件(在调用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("D:\\company\\soft\\C\\maopao_dll\\Debug\\maopao_dll.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;

 for(int i=0;i<10;i++)
  cout<<a[i]<<' ';
  cout<<endl;

 maopao1(a,10);
 for(int i=0;i<10;i++)
  cout<<a[i]<<' ';

 FreeLibrary(hdll);

}

 

把“unicode”改成支持多字符扩展

posted on 2016-09-22 13:39  程序员乌鸦  阅读(416)  评论(0编辑  收藏  举报

导航