zoukankan      html  css  js  c++  java
  • VC调用Delphi DLL

    别的没什么,是一定可以调用成功的。但是意外的是,ShowMessage函数在DLL里也可以轻易被调用。此外,Delphi里的var 相当于VC里的引用,需要在函数原型里正确标识,否则传递普通变量甚至常量是不行的。

    VC++代码:

    // callDLL.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    #include "windows.h"
    
    int main(int argc, char* argv[])
    {
        printf("Hello World!
    ");
        
        double a=10.4;
        HINSTANCE hDllInst = LoadLibrary("fonctionMathematique.DLL");    
        if(hDllInst)        
        {        
            typedef double (cdecl *MYFUNC)(double, double, double&); // 函数原型
            
            MYFUNC fun1 = NULL; // 函数别名        
            // fun1 = (MYFUNC)GetProcAddress(hDllInst,"_AddD"); // 函数名称
            fun1 = (MYFUNC)GetProcAddress(hDllInst,"_AddDouble"); // 在DLL中声明的函数名    
            
            if(fun1)            
            {            
                // printf("%f
    ",fun1(5.3));
                printf("%f
    ",fun1(1.1, 5.2, a));
                printf("%f
    ",a);
            }        
            FreeLibrary(hDllInst);        
        }
        return 0;
    }

    Delphi代码(代码太多,只列举关键函数实现部分):

     function _AddDouble(iVarA: Double; iVarB: Double; var iResult:Double):Double; cdecl; export;
     begin
       ShowMessage(FloatToStr(iVarA));
       iResult:=iVarA+iVarB;
       result:=iResult;
     end;
    
     function _AddD(a: double): double; cdecl;
     begin
        result:=a+10.1;
     end;

    另外,VC里可能默认使用cdecl方式。我没写传递方式就可以成功调用。

  • 相关阅读:
    python之网络编程
    python之面相对象进阶
    python之面相对象程序设计
    运行期优化
    切勿用普通的for循环遍历LinkedList
    NIO网络编程
    虚拟机字节码执行引擎
    AIO(异步IO)
    选择器(Selector)
    通道(Channel)
  • 原文地址:https://www.cnblogs.com/findumars/p/3565842.html
Copyright © 2011-2022 走看看