zoukankan      html  css  js  c++  java
  • C++ 动态链接库 显式调用

    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);
    
    }
  • 相关阅读:
    systemmap 使用记录
    reading code record
    吞吐问题
    debug cps 原因
    fopen的a+和rewind
    debug cps && perf debug
    tfo以及quic的阅读笔记
    ss 和netstat
    debug open files
    多核编程 local global
  • 原文地址:https://www.cnblogs.com/huacw/p/3088581.html
Copyright © 2011-2022 走看看