zoukankan      html  css  js  c++  java
  • C++调用dll

    很长时间没有用C++, 项目需要,重新温习下。

    假设需要调用的dll为dll_win32.dll,位置为C:dll中,实现的是两个变量相加的操作,函数名称为Add,步骤如下:

    1、新建一个project, 名字为console_win32

    2、console_win32.cpp代码如下:

      // console_win32.cpp : 定义控制台应用程序的入口点。
    //

    #include "stdafx.h"
    #include "iostream"
    #include <windows.h>
    typedef int (*DLLFunc)(int,int);
    using namespace std;
    int _tmain(int argc, _TCHAR* argv[])
    {
        DLLFunc dllFunc;
        int x;
        //HINSTANCE hInstLibrary = LoadLibrary("dll_win32.dll");
        HINSTANCE hInstLibrary =LoadLibraryEx("C:\dll\dll_win32.dll", NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
        if(hInstLibrary == NULL)
        {
            FreeLibrary(hInstLibrary);
        }
        else
        {
            dllFunc=(DLLFunc)GetProcAddress(hInstLibrary,"Add");//Add为dll中函数名称
            if(dllFunc==NULL)
            {
                FreeLibrary(hInstLibrary);
            }
            else
            {
                x=dllFunc(14,6);
                cout<<"mdc  "<<x<<endl;
                FreeLibrary(hInstLibrary);        
            }
        }
        return 0;
    }

  • 相关阅读:
    markdown语法
    GIT基本操作
    函数rest参数和扩展
    axios基础介绍
    Vue-Resource的使用
    Vue-router的介绍
    Vue2.0+组件库总结
    Vue 项目de一些准备工作
    VUE.js入门学习(5)- 插槽和作用域插槽
    VUE.js入门学习(4)-动画特效
  • 原文地址:https://www.cnblogs.com/csshaw/p/3958309.html
Copyright © 2011-2022 走看看