zoukankan      html  css  js  c++  java
  • VC调用Delphi制作的动态链接库如何互相传递字符串

    1、VC to Delphi

    Delphi源程序:

    library ExportChartData; 

    uses 
      SysUtils, 
      Classes; 

    {$R *.res} 

    const 
      DLL_VER      : Word 
    = $0001

    function GetVer: Word; 
    begin 
      Result :
    = DLL_VER; 
    end

    procedure SayHello(aString:pchar);cdecl; 
    begin 
      
    if aString = 'Hello!' then Beep; 
    end

    exports 
      GetVer, 
      SayHello; 

    begin 
    end.

    VC源程序

    // TestInterface.cpp : Defines the entry point for the console application.
    //

    #include 
    "stdafx.h"
    #include 
    <windows.h>

    int main(int argc, char* argv[])
    {
    char *szDllName = "..\\..\\OBJ\\ExportChartData.dll";
    HINSTANCE hInstance 
    = LoadLibrary(szDllName);

    if (hInstance != NULL)
    {
      
    void (*f)(char &= (void (*)(char &))GetProcAddress(hInstance, "SayHello");
      
    char *= "Hello!";
       f(
    *s);
    }
    FreeLibrary(hInstance);

    return 0;
    }

    2、Delphi to VC

    Delphi源程序

    library ExportChartData; 

    uses 
      SysUtils, 
      Classes; 

    {$R *.res} 

    const 
      DLL_VER      : Word 
    = $0001

    function GetVer: Word; 
    begin 
      Result :
    = DLL_VER; 
    end

    procedure SayHello(index:Integer;aString:pchar);cdecl; 
    begin 
      
    if index = 0 then strcopy(aString,'A Test for Pass String!'
      
    else 
        strcopy(aString,
    'OK!'); 
    end

    exports 
      GetVer, 
      SayHello; 

    begin 
    end

    VC源程序

    // TestInterface.cpp : Defines the entry point for the console application.
    //

    #include 
    "stdafx.h"
    #include 
    <windows.h>
    #include 
    <stdio.h>

    typedef 
    char* PCHAR;

    int main(int argc, char* argv[])
    {
    PCHAR szDllName 
    = "..\\..\\OBJ\\ExportChartData.dll";
    HINSTANCE hInstance 
    = LoadLibrary(szDllName);
    char *= new char[255];

    if (hInstance != NULL)
    {
      
    void (*f)(intchar *= (void (*)(intchar *))GetProcAddress(hInstance, "SayHello");
       f(
    1, s);
       printf(
    "%s",s);
    }
    FreeLibrary(hInstance);
    delete[]s;

    return 0;
    }

  • 相关阅读:
    【递归】斐波那契数列第n个数
    二分查找【循环和递归】
    递归:正序、逆序输出一个正整数的各位数字
    Ubuntu x86-64汇编(5) 控制指令
    Ubuntu x86-64汇编(4) 数值操作指令
    Ubuntu x86-64汇编(3) 数值操作指令
    给X240换上了三键触摸板
    Ubuntu x86-64汇编(2)
    Ubuntu x86-64汇编(1)
    X240 Ubuntu18.04安装流水帐
  • 原文地址:https://www.cnblogs.com/yunhaisoft/p/1239687.html
Copyright © 2011-2022 走看看