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

  • 相关阅读:
    Leetcode: Max Consecutive Ones II(unsolved locked problem)
    Leetcode: Find Permutation(Unsolve lock problem)
    G面经: Design Stock Price Display System
    U面经Prepare: Print Binary Tree With No Two Nodes Share The Same Column
    U面经Prepare: Web Address
    FG面经Prepare: BST to Double LinkedList
    G面经Prepare: Longest All One Substring
    G面经Prepare: Print Zigzag Matrix
    FG面经: Interval问题合集
    2017.10 有感而发(小结)
  • 原文地址:https://www.cnblogs.com/yunhaisoft/p/1239687.html
Copyright © 2011-2022 走看看