VC如何调用DELPHI编写返回为字符串的DLL

SKY1006 2017-06-14 01:30:01
这个VC调用Delphi返回值为整型的DLL示例
int(__stdcall * ReadPrintCountR)(int pa);
HINSTANCE hDll3 = LoadLibrary("Print.DLL");
ReadPrintCountR = (int(__stdcall *)(int pa))(GetProcAddress(hDll3, "ReadPrintCount"));
int p = ReadPrintCountR(0);
FreeLibrary(hDll3);

----------------------------------------------------------------------------------------------------
那么VC调用返回值为字符的调用应该怎么写?要求调用后的返回值用edit文本框显示
delphi里的编写的返回字符的原型函数的DLL是这样写的

function GetValue(pchar1:pchar):pchar;stdcall;
implementation
{$R *.dfm}
function GetValue(pchar1:Pchar):PChar;
var str:string;
begin
frmPrint:=TfrmPrint.Create(Application);
str:='这是delphi返回的'+string(pchar1);
Result:=pchar(Str);
frmPrint.Free;
end;
-------------------------------------------------------------------------------------------------------------------
delphi调用这个DLL已可以,delphi调用示例如下,请问用VC调用实现如下功能怎么调用?

function GetValue(Phar1:Pchar):PChar;stdcall;External 'Print.dll';

procedure TForm1.btn1Click(Sender: TObject);
var str1,str2:string;
begin
str2:='123';
str1:= string( GetValue(PChar(str2)) );
edt1.Text:=str1;
ShowMessage(str1);
end;

...全文
735 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

7,540

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 VC.NET
社区管理员
  • VC.NET社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧