unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,ComCtrls,ShellApi,ComObj, ExtCtrls;
  function RegisterOleFile (strOleFileName : STRING ) : BOOLEAN;
type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    Edit1: TEdit;
    ListBox1: TListBox;
    Timer1: TTimer;
    Button2: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  m_dt:variant;
  TID:String;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  RegisterOleFile(ExtractFilePath(Application.Exename)+'HYDati.dll');
  m_dt:=CreateOleObject('HYDati.Dati');
 
end;

//注册COM组件
function RegisterOleFile (strOleFileName : STRING ) : BOOLEAN;
	const
		RegisterOle = 1;//注册
		UnRegisterOle = 0;//卸载

	type 
		TOleRegisterFunction = function : HResult;//注册或卸载函数的原型

	var
		hLibraryHandle : THandle;//由LoadLibrary返回的DLL或OCX句柄
		hFunctionAddress: TFarProc;//DLL或OCX中的函数句柄，由GetProcAddress返回
		RegFunction : TOleRegisterFunction;//注册或卸载函数指针
	begin
		Result := FALSE;
		//打开OLE/DCOM文件，返回的DLL或OCX句柄
		hLibraryHandle := LoadLibrary(PCHAR(strOleFileName));
		if (hLibraryHandle > 0) then //DLL或OCX句柄正确 
		try 
			//返回注册函数的指针
			hFunctionAddress := GetProcAddress(hLibraryHandle, pchar('DllRegisterServer'));
			if (hFunctionAddress <> NIL) then//注册函数存在
			begin 
				RegFunction := TOleRegisterFunction(hFunctionAddress);//获取操作函数的指针 
				if RegFunction >= 0 then //执行注册或卸载操作，返回值>=0表示执行成功
					result := true; 
			end
      else
        MessageBox(0, '没找到DLL的接口DllRegisterServer!','提示信息',64)
		finally
		FreeLibrary(hLibraryHandle);//关闭已打开的OLE/DCOM文件
	end;
end;



procedure TForm1.Button1Click(Sender: TObject);
begin
TID := m_dt.SendImage(Edit1.Text, 1, 1, 300, 200,1000, 300,1,'');
   

ListBox1.Items.Add('发送截图');
 ListBox1.Items.Add(TID)   ;
 Timer1.Enabled:=True;


end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
Answer: String;

begin
    Answer:=m_dt.GetAnswer(TID);
    if  Length(Answer)>0  then
    begin
      Timer1.Enabled:=False;
      ListBox1.Items.Add(Answer)   ;
    end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
strPth:string; 

begin
strpth:=Getcurrentdir(); 

TID := m_dt.SendFile(Edit1.Text, strpth+'\示范.bmp', 1000,60,1,'');

ListBox1.Items.Add('发送图片');
ListBox1.Items.Add(TID)   ;
Timer1.Enabled:=True;


end;

end.




 
