NRabbit

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

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;
}
posted on 2009-07-28 12:38  kevin.nrabbit  阅读(1078)  评论(0编辑  收藏  举报