一个dll的调用问题 ( 积分: 50 )

  • 主题发起人 主题发起人 cooldren
  • 开始时间 开始时间
C

cooldren

Unregistered / Unconfirmed
GUEST, unregistred user!
一个发短信的接口
有VB的调节器用过程,成功注册组件后,在VB的“工程—引用—浏览”中,选择MsgSDK.dll,点确定。使用时,变量声明部分先声明(如Dim Sendsms As MsgSDK.sms),之后在调用函数之前创建一个实例(Set Sendsms As New MsgSDK.sms),然后就可以调用DLL中的各个函数(如rslt=Sendsms.GetInfo(username,password))了,但我在delphi中就调用不成功,不论是静态的还是动态的。
unit Main;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TMainFrm = class(TForm)
Button1: TButton;
edt: TEdit;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private

public
{ Public declarations }

end;

var
MainFrm: TMainFrm;

implementation

{$R *.dfm}
function GetInfo(Username:pchar;Password:pchar):pchar;stdcall;external 'MsgSDK.dll' name 'getinfo';

type TGetFee=function(Username:pchar;Password:pchar):pchar;
procedure TMainFrm.Button2Click(Sender: TObject);
var
// Sendsms:MsgSDK.sms ; //看VB里面,好像要定义一下,再create,过不去
aa:string;
begin
// GetInfo(pchar('aaa'),pchar('aaa')); //出错,无法定位getinfo
end;


procedure TMainFrm.Button1Click(Sender: TObject);
var
hHandle:THandle;
GetInfo:TGetInfo;

begin
hHandle:=LoadLibrary('MsgSDK.dll');
if hHandle>=32 then
begin
showmessage('loadOK');
@GetInfo:=GetProcAddress(hHandle,pchar('GetInfo'));
if @GetInfo<>nil then
begin
showmessage('OK');
edt.text:=GetInfo('daymoney','qqaazz');
end
else
showmessage('nil'); [red]//总是提示nil[/red]
FreeLibrary(hHandle);
end;

end;
 
这个DLL是不是VB写的,VB写的DLL好像要注册,并且要按ActiveX那套去调用,不是一个简半的DLL
------------------------------------------------------
http://www.waibaoinfo.com 外包信息网
 
拷到system32下面并用regsvr32注册了的,用eXeScope看了下
MsgSDK;

Dispatch _sms;
GUID={730896BA-88BF-4F57-AEE1-F5F9B96DD089};
function QueryInterface(riid:^GUID; out ppvObj:^^void);
function AddRef: UI4;
function Release: UI4;
function GetTypeInfoCount(out pctinfo:^UINT);
function GetTypeInfo(itinfo:UINT; lcid:UI4; out pptinfo:^^void);
function GetIDsOfNames(riid:^GUID; rgszNames:^^I1; cNames:UINT; lcid:UI4; out rgdispid:^I4);
function Invoke(dispidMember:I4; riid:^GUID; lcid:UI4; wFlags:UI2; pdispparams:^DISPPARAMS; out pvarResult:^variant; out pexcepinfo:^EXCEPINFO; out puArgErr:^UINT);
function GetUrlFile(out stUrl:^BSTR): BSTR;
function GetInfo(out Username:^BSTR; out Password:^BSTR): variant;
function GetFee(out Username:^BSTR; out Password:^BSTR): variant;
function ModifyPSW(out Username:^BSTR; out Password:^BSTR; out NewPassword:^BSTR; out KeyWord:^BSTR): variant;
function MT(out Username:^BSTR; out Password:^BSTR; out Mobile:^BSTR; out Content:^BSTR; out KeyWord:^BSTR): variant;
function MO(out Username:^BSTR; out Password:^BSTR): variant;

Class sms;
GUID={C7E6A3D2-4CD7-4FBF-A8CB-E9F6914F9AAC};
function QueryInterface(riid:^GUID; out ppvObj:^^void);
function AddRef: UI4;
function Release: UI4;
function GetTypeInfoCount(out pctinfo:^UINT);
function GetTypeInfo(itinfo:UINT; lcid:UI4; out pptinfo:^^void);
function GetIDsOfNames(riid:^GUID; rgszNames:^^I1; cNames:UINT; lcid:UI4; out rgdispid:^I4);
function Invoke(dispidMember:I4; riid:^GUID; lcid:UI4; wFlags:UI2; pdispparams:^DISPPARAMS; out pvarResult:^variant; out pexcepinfo:^EXCEPINFO; out puArgErr:^UINT);
function GetUrlFile(out stUrl:^BSTR): BSTR;
function GetInfo(out Username:^BSTR; out Password:^BSTR): variant;
function GetFee(out Username:^BSTR; out Password:^BSTR): variant;
function ModifyPSW(out Username:^BSTR; out Password:^BSTR; out NewPassword:^BSTR; out KeyWord:^BSTR): variant;
function MT(out Username:^BSTR; out Password:^BSTR; out Mobile:^BSTR; out Content:^BSTR; out KeyWord:^BSTR): variant;
function MO(out Username:^BSTR; out Password:^BSTR): variant;

主要这个sms;
他的说明文档,VB的,说是标准的com 组件,delphi是可以调用的
Dim Sendsms As MsgSDK.sms
Set Sendsms As New MsgSDK.sms
rslt=Sendsms.GetInfo(username,password)


不知道在delphi怎么创建这个 MsgSDK.sms ,请高手指教。
谢谢
 
已经解决了,谢谢rtl的提醒
 
后退
顶部