有个com类型的Dll,我怎么调用里面的函数呢? (100分)

  • 主题发起人 牧羊狐
  • 开始时间

牧羊狐

Unregistered / Unconfirmed
GUEST, unregistred user!
我这样调用的
……
type
TGetPwd = procedure(const InStr: WideString;
out PassStr: OleVariant);
……
procedure TFrmMain.BtnOkClick(Sender: TObject);
var
GetPwd: TGetPwd;
Handle: THandle;
begin
Handle := LoadLibrary('Password.dll');
if Handle <> 0 then
begin
@GetPwd := GetProcAddress(Handle, 'GetPassword');
if @GetPwd <> nil then
begin
showmessage('OK');
end;
end;
end;

结果总是跳过 showmessage('OK');
可这个dll明明有那个函数!!
 
既然是COM,应该先建立COM对象,然后再调用它的接口函数。
你还没有建立COM对象!
 
const exGUID: TGUID = '{506E305A-18AD-4971-80B3-C85861327A38}';
try
xExChange := CreateRemoteComObject('localhost', exGUID) as IDispatch;
except
xExChange := CreateoleObject('xHY2000.xHY');
end;
xExChange.ZPgl('货运部','hya');
 
SocketConnection1.Host:='127.0.0.1';
SocketConnection1.ServerName := ''Password.ComObject';
SocketConnection1.Connected := True;
SocketConnection1.AppServer.GetPassword(……);
SocketConnection1.Close;
 
1.Procedure本来就是一个pointer,所以去掉@即可
GetPwd := GetProcAddress(Handle, 'GetPassword');
if GetPwd <> nil then
begin

2. password.dll必须在system32目录下
 
多人接受答案了。
 
顶部