感谢昨晚的几位的解答,小虾谢了分儿也给了.
http://expert.csdn.net/Expert/topic/1690/1690082.xml?temp=.7899897新问题如下:
用VC 写DLL在delphi 中用,原函数如下: __declspec(dllexport) int _stdcall WriteA(struct cardinfo *cardinfo);
__declspec(dllexport) int _stdcall WriteB(unsigned char *key); __declspec(dllexport) int _stdcall OpenCom(int com, long baud);
cardinfo 为结构体. 动态连接库为a.dll
大虾们给俺再解答一下吧,分儿继续给!
主要是关于参数的如何引用!
http://expert.csdn.net/Expert/topic/1690/1690082.xml?temp=.7899897新问题如下:
用VC 写DLL在delphi 中用,原函数如下: __declspec(dllexport) int _stdcall WriteA(struct cardinfo *cardinfo);
__declspec(dllexport) int _stdcall WriteB(unsigned char *key); __declspec(dllexport) int _stdcall OpenCom(int com, long baud);
cardinfo 为结构体. 动态连接库为a.dll
大虾们给俺再解答一下吧,分儿继续给!
主要是关于参数的如何引用!
解决方案 »
- 急 !!怎样把Form1中edit控件中的值传给Form2中edit控件中
- 诸位大虾,错误信息题目:SQL SERVER OLEDB PROVIDER SUPPORT ERROR
- 超难问题!!!! 如何 修改 cxDateEdit 控件 下拉 选择日期 里面 按钮 文字???? 急!!!!!!!!
- *****自己当老板,但是需要伙伴,不是聘用,是合作*****
- 日期的问题,
- 请问,为什么我这几天的分数不增加呢?
- 程序员好书征集!(有回报的哦)
- 关于ActiveForm的一个简单问题
- 简单问题,如何一个表中的字段不为空,且默认为指定值.
- 容易的问题
- project->option中的forms页中的form选择问题
- 收到一封奇怪的邮件,删不掉?
//声明动态调用的过程
TGstr = function():Pchar;stdcall; //函数的声明
TMYProc = procedure(var inhandle:HWND; instring:pchar);stdcall; //是否使用stdcall要依DLL文件决定
//注意静态调用时stdcall的位置
//静态调用动态库
procedure messageshow( var inhandle:HWND; instring:pchar);stdcall; external 'D:\MyProject\DELPHI\动态库的调用\动态库文件\dllformp.dll';
function GetString():Pchar;stdcall;external 'D:\MyProject\DELPHI\动态库的调用\动态库文件\dllformp.dll';
//方法二用name引出
//procedure messagesho( var inhandle:HWND; instring:pchar);stdcall; external 'D:\MyProject\DELPHI\动态库的调用\动态库文件\dllformp.dll' name 'messageshow';
var
Form1: TForm1;
MyLib:THandle;
i:integer;
implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);var
temp:Pchar;
AHandle:HWND;
begin
temp:='呵呵,你好啊!';
AHandle:=application.Handle;
edit1.Text:=getstring();
messageshow(AHandle,temp);
edit1.Text:='';
end;procedure TForm1.Button2Click(Sender: TObject);
var
temp1:Pchar;
UHandle:HWND;
P:TMYproc;
G:TGstr;
begin
temp1:='呵呵,你好啊!';
UHandle:=application.Handle;
if MyLib>0 then
begin @G:=getprocaddress(mylib,'GetString'); //调用入口
if @G<>nil then
begin
edit1.Text:=G();
end
else
showmessage('没有找到函数的入口'); @p:=GetProcAddress(mylib,'messageshow');
if @p<>nil then
begin
p(UHandle,temp1);
end
else
showmessage('没有找到函数的入口'); edit1.Text:='';
end
else
showmessage('函数加载失败!');
end;procedure TForm1.Button3Click(Sender: TObject);
begin
messagebeep(0);
TIMER1.Enabled:=TRUE;
end;procedure TForm1.Timer1Timer(Sender: TObject); //加载动态资源,动态库在FORM CREATE 中加载
var
IconHand:THandle;
begin
if isiconic(application.Handle) then
begin
if i>9 then
i:=1; iconhand:=loadicon(mylib,Pchar('ICON'+INTTOSTR(I)));
if iconhand<> 0 then
application.Icon.Handle:=iconhand
else
showmessage('can''t find icon!');
inc(i);
end;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
MyLib:=LoadLibrary('D:\MyProject\DELPHI\动态库的调用\动态库文件\dllformp.dll');
if mylib=0 then
begin
showmessage('Can''t Load The Dll!');
application.Terminate;
end;
i:=1;
end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
freelibrary(mylib);
end;end.
function WriteA(cardinfo:pointer):Integer; stdcall; external 'a.dll';
function WriteB(key:string):Integer; stdcall; external 'a.dll';
function OpenCom(com:Integer;baud:longint):Integer; stdcall; external 'a.dll';
不一定对,试试看?
type
Pcardinfo=^cardinfo;
function WriteA(cardinfo:Pcardinfo):Integer; stdcall; external 'a.dll';
function WriteB(key:PChar):Integer; stdcall; external 'a.dll';
function OpenCom(com:Integer;baud:longint):Integer; stdcall; external 'a.dll';
http://expert.csdn.net/Expert/topic/1645/1645329.xml?temp=.5758631
struct cardinfo
{
cardid[6];
cardunit[10];
};
那么在dephi 中结构体如何定义?