首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

根据TLB文件调用另外一个EXE文件,总不成功.该如何解决

2012-02-02 
根据TLB文件调用另外一个EXE文件,总不成功.有一个客户端软件,连接远端服务器。现在我有DLL文件,TLB文件。可

根据TLB文件调用另外一个EXE文件,总不成功.
有一个客户端软件,连接远端服务器。现在我有DLL文件,TLB文件。可我自己写的代码没有办法连接远端服务器。请大家帮助一下。
我如果先启动这个软件,我执行我写代码,原软件就可以能显示连接成功,如果我不启动软件,就没有办法连接。

TLB中有一段如下.
//   *********************************************************************//
//   DispIntf:     _IApplicationEvents
//   Flags:           (4096)   Dispatchable
//   GUID:             {3C31BF76-2837-4BFA-A19E-34485A213F29}
//   *********************************************************************//
    _IApplicationEvents   =   dispinterface
        [ '{3C31BF76-2837-4BFA-A19E-34485A213F29} ']
        procedure   ReceiveCurConf(var   Conf:   OleVariant);   dispid   1;
        procedure   StatusChange(Status:   Integer;   const   bstrDetail:   WideString);   dispid   2;
    end;

//   *********************************************************************//
//   *********************************************************************//
//   Interface:   IApplication
//   Flags:           (4416)   Dual   OleAutomation   Dispatchable
//   GUID:             {98AA9DD3-0715-4170-8A96-04F06C8BAD49}
//   *********************************************************************//
    IApplication   =   interface(IDispatch)
        [ '{98AA9DD3-0715-4170-8A96-04F06C8BAD49} ']
        procedure   Connect(shType:   Smallint;   const   bstrServerIP:   WideString;   const   bstrUser:   WideString;  
                                            const   bstrPass:   WideString);   safecall;
        procedure   DisConnect;   safecall;
        function   IsConnect:   Smallint;   safecall;
        function   GetSessions:   IDispatch;   safecall;
        procedure   Exit;   safecall;
        procedure   ShowServer;   safecall;
        function   GetCurrentAccount:   WideString;   safecall;
        function   GetCurrentHost:   WideString;   safecall;
    end;

//   *********************************************************************//
//   DispIntf:     IApplicationDisp
//   Flags:           (4416)   Dual   OleAutomation   Dispatchable
//   GUID:             {98AA9DD3-0715-4170-8A96-04F06C8BAD49}
//   *********************************************************************//
    IApplicationDisp   =   dispinterface
        [ '{98AA9DD3-0715-4170-8A96-04F06C8BAD49} ']
        procedure   Connect(shType:   Smallint;   const   bstrServerIP:   WideString;   const   bstrUser:   WideString;  
                                            const   bstrPass:   WideString);   dispid   1;
        procedure   DisConnect;   dispid   2;


        function   IsConnect:   Smallint;   dispid   3;
        function   GetSessions:   IDispatch;   dispid   4;
        procedure   Exit;   dispid   5;
        procedure   ShowServer;   dispid   6;
        function   GetCurrentAccount:   WideString;   dispid   7;
        function   GetCurrentHost:   WideString;   dispid   8;
    end;

//   *********************************************************************//
//   The   Class   CoSession   provides   a   Create   and   CreateRemote   method   to                    
//   create   instances   of   the   default   interface   ISession   exposed   by                            
//   the   CoClass   Session.   The   functions   are   intended   to   be   used   by                          
//   clients   wishing   to   automate   the   CoClass   objects   exposed   by   the                  
//   server   of   this   typelibrary.                                                                                        
//   *********************************************************************//


以下是我自己写的:

unit   Unit1;

interface

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

type
    TForm1   =   class(TForm)
        Button1:   TButton;
        Button2:   TButton;
        Button3:   TButton;
        Button4:   TButton;
        Memo1:   TMemo;
        procedure   Button1Click(Sender:   TObject);
        procedure   Button3Click(Sender:   TObject);
        procedure   Button4Click(Sender:   TObject);
        procedure   Button2Click(Sender:   TObject);
    private
        {   Private   declarations   }
    public
        {   Public   declarations   }
    end;

var
    Form1:   TForm1;

implementation
var   etermapp   :   IApplication;


{$R   *.dfm}

procedure   TForm1.Button1Click(Sender:   TObject);
var   ip,name,pass:   string;
var   v   :   variant;
begin
    ip   :=   'x.x.x.x ';
    name   :=   'xxxxx ';
    pass   :=   'xxxxx ';


    etermapp   :=   CoApplication.Create;
    etermapp.Connect(0,ip,name,pass);
end;

procedure   TForm1.Button3Click(Sender:   TObject);
begin
      ShowMessage( 'isconn? '+ '       '+IntToStr(etermapp.IsConnect));
end;

procedure   TForm1.Button4Click(Sender:   TObject);
begin
  etermapp   :=   nil;
  Form1.Close;
end;

procedure   TForm1.Button2Click(Sender:   TObject);
begin
    etermapp.ShowServer;
end;

end.

哪里错了,还是我的思路错了,请大家指教

[解决办法]
没弄懂

热点排行