VC调用Delphi制作的动态链接库如何互相传递字符串
2009-07-28 12:38
731 查看
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 *s = "Hello!";
f(*s);
}
FreeLibrary(hInstance);
return 0;
}
2、Delphi to VC
[b]Delphi源程序[/b]
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 *s = 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;
}
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 *s = "Hello!";
f(*s);
}
FreeLibrary(hInstance);
return 0;
}
2、Delphi to VC
[b]Delphi源程序[/b]
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 *s = 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;
}
相关文章推荐
- VC调用Delphi制作的动态链接库如何互相传递字符串
- VC调用Delphi制作的动态链接库如何互相传递字符串
- VC调用Delphi制作的动态链接库如何互相传递字符串
- Delphi中如何调用VC++创建的动态链接库
- VC++ 6.0如何创建与调用动态链接库
- VC++ 6.0如何创建与调用动态链接库
- VC++如何创建与调用动态链接库
- c#中如何调用vc++写的动态链接库
- 在Delphi中调用VC++创建的动态链接库的Demo
- VC++ 6.0如何创建与调用动态链接库
- Delphi中怎么调用VC++创建的动态链接库
- VC++ 6.0如何创建与调用动态链接库
- 在Delphi中调用VC++创建的动态链接库的实例
- VC++ 6.0如何创建与调用动态链接库
- WinCE设备动态链接库的制作与调用
- Delphi中动态生成的button调用onclick如何传递参数
- Delphi调用C#动态链接库DLL(摘自网络)
- 如何在django的filter中传递字符串变量作为查询条件(动态改变查询条件)
- 如何用Delphi调用由VC开发的ATL/COM服务,并响应其事件
- 【转】C#生成dll文件:如何用C#编译生成dll文件即动态链接库文件供其它程序调用