链节文件如下:library mymath;{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }uses
SysUtils,
Windows,
Classes,
Messages,
Graphics, Controls, Forms,ExtCtrls,
Dialogs;{$R *.res}
procedure transfer(s:string);
begin
Application.MessageBox(PChar(s),'提示',0);
end;function sqr(num,number:integer):integer;export;
begin
sqr:=num*num*number;
end;exports
sqr,transfer;
begin
end.
链节文件执行后是成功的。
C#调用Delphi7.0写的链节文件mymath.dll代码如下:
[DllImport("mymath.dll", EntryPoint = "sqr", CharSet = CharSet.Auto)]
static extern int AA([In,Out]int a, int b);
[DllImport("mymath.dll", CharSet = CharSet.Auto
static extern void transfer(string s);
private void button7_Click(object sender, EventArgs e)
{ this.Text = AA(3,4).ToString();
string s = "aaaaaaa";
transfer(s);
}
其中执行this.Text = AA(3,4).ToString();后显示为0
执行transfer(s);后弹出的对话框内容本应该为"aaaaaaa",但却显示为空,请大侠相助,谢了
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }uses
SysUtils,
Windows,
Classes,
Messages,
Graphics, Controls, Forms,ExtCtrls,
Dialogs;{$R *.res}
procedure transfer(s:string);
begin
Application.MessageBox(PChar(s),'提示',0);
end;function sqr(num,number:integer):integer;export;
begin
sqr:=num*num*number;
end;exports
sqr,transfer;
begin
end.
链节文件执行后是成功的。
C#调用Delphi7.0写的链节文件mymath.dll代码如下:
[DllImport("mymath.dll", EntryPoint = "sqr", CharSet = CharSet.Auto)]
static extern int AA([In,Out]int a, int b);
[DllImport("mymath.dll", CharSet = CharSet.Auto
static extern void transfer(string s);
private void button7_Click(object sender, EventArgs e)
{ this.Text = AA(3,4).ToString();
string s = "aaaaaaa";
transfer(s);
}
其中执行this.Text = AA(3,4).ToString();后显示为0
执行transfer(s);后弹出的对话框内容本应该为"aaaaaaa",但却显示为空,请大侠相助,谢了
解决方案 »
- contextmenustrip 怎么获取子菜单,怎么返回上一层
- Lambda表达式求解!!!!
- 提一个关于XPO的问题(ORM的一个框架),希望用过的人回答下。
- Hi. 那位高手有空,想请高手推荐三本 ---- 关于 C# 开发桌面软件的书.
- treeView的问题`` 求助`` 在线等``
- 求助:C# 网页上无法弹出控制台窗口。
- 怎样才能使winform产生的exe 文件在其他电脑中可以运行
- 向各位兄弟请都一个关于表格控件的问题!!!!
- 高手来,与手写板连接!!!
- 将二维数组转化成实现IListSource 或 IEnumerable接口的对象,选哪个最好?
- 喜欢看电影的就发分啊
- datagrid中格式化字符串的问题
procedure transfer(s:PChar);delphi中如果使用string类型,c#无法调用。
试过了,弹出的对话框还是空的,能不能再帮下忙?
其中:[DllImport("mymath.dll", CharSet = CharSet.Auto后少个中括号"]"是我无意中删掉了,而并不是原程序中的错误点
[DllImport("mymath.dll"]
static extern void transfer(
[MarshalAs(UnmanagedType.LPTStr)]string s);
是不是我delphi中或c#中哪写的有错误?弹出的对话框还是空的。
另外this.Text = AA(3,4).ToString();执行后仍显示为0
procedure transfer(s:PChar);这种形式了