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)( int char   * =  ( void  ( * )( int char   * ))GetProcAddress(hInstance,  " SayHello " );
   f(
1 , s);
   printf(
" %s " ,s);
}
FreeLibrary(hInstance);
delete[]s;

return   0 ;
}

转载于:https://www.cnblogs.com/yunhaisoft/archive/2008/07/10/1239687.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值