VC调用Delphi制作的动态链接库如何互相传递字符串
2020-02-17 11:08
423 查看
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
[strong]Delphi源程序[/strong]
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 th 1fa48 e 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;
}
转载于:https://www.cnblogs.com/yunhaisoft/archive/2008/07/10/1239687.html
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- Delphi 中用 GetEnvironmentVariable 获取常用系统变量
- Speed up the display of Delphi list components
- 用Delphi写ActiveX的经验
- Delphi6利用WebService 编写 SendEMail程序
- delphi 中分隔符分隔的字符串
- Delphi快速从文件流读取数据存入本地txt
- Delphi Opendialog用法
- Delphi选择指定路径作为操作路径
- [转]Delphi 12种大小写转换的方法
- 如何给ActiveX数字签名(Step by Step, Delphi)
- Delphi还是那个Delphi,变化了的只是世界
- 再执牛耳,Delphi的安卓开发,效率与性能兼而有之,比之鱼与熊掌
- Delphi的资料和教程,多多的
- delphi中TreeView使用常见问题
- 用delphi写下载程序
- delphi技巧--分离汉字和英文字母
- delphi中var关键字
- Delphi和C++ Builder中的Hibernate开发(一)
- Delphi和C++ Builder中的Hibernate开发(六)
- 关于C#下写的Web Service 服务在Delphi下调用时的问题