有关VC写的DLL的调用,急!(在线等)(100分)

  • 主题发起人 主题发起人 Maxcjh
  • 开始时间 开始时间
M

Maxcjh

Unregistered / Unconfirmed
GUEST, unregistred user!
unit SMS;<br>interface<br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs;<br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br>&nbsp; Sms_Ini = function( userName:String; &nbsp;password:String; &nbsp;userID:integer): integer; &nbsp; &nbsp;//不知这行有没有写错<br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>Var<br>&nbsp;LibHandle:HWND;<br>&nbsp;PFunc: TFarProc;<br>&nbsp;i:integer;<br>begin<br>LibHandle:=LoadLibrary('SmsApi201.dll');<br>&nbsp;PFunc:=GetProcAddress(LibHandle,'Sms_Ini');<br>&nbsp; &nbsp;i:=Sms_Ini(PFunc)('','',1); &nbsp; &nbsp;----------------------此行报地址访问错<br>&nbsp; &nbsp;FreeLibrary(LibHandle);<br>end;<br>end.<br><br>其中Sms_Ini的原型为:<br>unsigned long __declspec (dllexport) Sms_Ini(<br>&nbsp; &nbsp; &nbsp;char *pcUsrName,<br>&nbsp; &nbsp; &nbsp;char *pcPassWord,<br>&nbsp; &nbsp; &nbsp;DWORD dwUsrID);<br>请问我应怎么写才对。<br><br><br>
 
注意调用协议 <br>Sms_Ini = function( userName:String; &nbsp;password:String; &nbsp;userID:integer): integer; cdecl;
 
uses <br>&nbsp; ....Types....<br>Type<br>...<br>&nbsp; TSms_Ini = function( userName: PChar; &nbsp;password: PChar; &nbsp;userID: DWORD): integer; &nbsp; cdecl; <br>....<br>procedure TForm1.FormCreate(Sender: TObject);<br>Var<br>&nbsp;LibHandle:HWND;<br>&nbsp;//PFunc: TFarProc;<br>&nbsp;Func: TSms_Ini; <br>&nbsp;i:integer;<br>begin<br>&nbsp; LibHandle:=LoadLibrary('SmsApi201.dll');<br>&nbsp; if LibHandle &lt;= 0 then exit;<br>&nbsp; @Func:= GetProcAddress(LibHandle,'Sms_Ini');<br>&nbsp; if not assigned(Func) then exit;<br>&nbsp; i:=Sms_Ini(PFunc)('','',1); &nbsp; &nbsp;----------------------此行报地址访问错<br>&nbsp; FreeLibrary(LibHandle);<br>end;<br>......
 
我还想问以下这个VC的函数原型写成DELPHI的我应怎么写才对。<br>unsigned long __declspec(dllexport) GetModl(<br>&nbsp; &nbsp; BYTE* bDev,<br>&nbsp; &nbsp; BYTE* bModl,<br>&nbsp; &nbsp; BYTE bModlTyp,<br>&nbsp; &nbsp; BYTE bWorkTyp,<br>&nbsp; &nbsp; const char* pcModuleIsdnNum);<br>
 
VC++不熟,不过加*的参数应该是传指针吧,要用var<br>声明加个safecall试试
 
多人接受答案了。
 
后退
顶部