请高手看看我的程序为什么不对啊!! (100分)

  • 主题发起人 主题发起人 lsc0530
  • 开始时间 开始时间
L

lsc0530

Unregistered / Unconfirmed
GUEST, unregistred user!

library Project2;
uses
ComServ,
Unit1 in 'Unit1.pas';
exports
DllGetClassObject,
DllCanUnloadNow,
DllRegisterServer,
DllUnregisterServer;
{$R *.RES}
begin
end.

unit Unit1;
interface
uses
Windows,Messages,ComObj,ComServ,SysUtils,Classes,Graphics,Controls,Forms,Dialogs,shellapi,shlobj,ActiveX;
const
CLSID_PascalcopHook:TGUID='{80A06FA0-7DF2-11D0-98D0-444553540000}';
type
ICopyHookA=interface(IUnKnown)
function CopyCallback(Hwnd:THandle;wFunc,
wFlags:UINT;pszSrcFile:PAnsiChar;dwSrcAttribs:DWORD;
pszDestFile:PAnsiChar;dwDestAttribs:DWORD):UINT;
end;
ICopyHook=ICopyHookA
type
TpasCopyHooK=class(TComObject,ICopyHook)
public
function CopyCallback(Hwnd:THandle;wFunc,
wFlags:UINT;pszSrcFile:PAnsiChar;dwSrcAttribs:DWORD;
pszDestFile:PAnsiChar;dwDestAttribs:DWORD):UINT;stdcall;
end;

implementation
function TpasCopyHooK.CopyCallback(Hwnd:THandle;wFunc,wFlags:UINT;pszSrcFile:PAnsiChar;dwSrcAttribs:DWORD;pszDestFile:PAnsiChar;dwDestAttribs:DWORD):UINT;stdcall;
var
Msg:string;
MessType:TMsgDlgType;
begin
Application.Handle:=Hwnd;
Msg:='';
MessType:=mtconfirmation;
case wFunc of
FO_COPY:
begin
Msg:=Format('Are yopu sure you want to copy the %s'+'folder to the %s destination ',[PszSrcFile,pszDestFile]);
end;
FO_DELETE:
begin
Msg:=Format('Are yopu sure you want to del the %s',[PszSrcFile,pszDestFile]);
end;
end;
if msg<>'' then
result:=messageDlg(Msg,MessType,mbYesNoCancel,0 )
else
result:=id_Yes;
end;
initialization
TComObjectFactory.Create(comserver,TPasCopyHook,CLSID_PascalcopHook,'PasalCopyHook','CopyHook Demo from Mastering Delphi 3',ciMultiInstance);

end.
 
它是说你的TpasCopyHooK中的CopyCallback的定义与ICopyHookA中的CopyCallback不相符!
对对代码,不要总相信书。那东西是人写的,可能有错误的。还有你的代码不会在编辑
器里就这样写吧?
换换行呀。
 
//找到原因了,是前导声名的事。你吧ICopyHookA的声明提前就可以了。
//注意给你改了部分细节,但功能没有改动。
unit Unit1;

interface
uses
Windows,Messages,ComObj,ComServ,SysUtils,Classes, Graphics,
Controls,Forms,Dialogs,shellapi,shlobj,ActiveX;
const
CLSID_PascalcopHook:TGUID='{80A06FA0-7df2-11D0-98D0-444553540000}';

type
//注意这里把你那多余的重命名给去掉了。
ICopyHookA=interface(IUnKnown)
function CopyCallback(Hwnd:THandle;
wFunc, wFlags:UINT;
pszSrcFile: PAnsiChar;
dwSrcAttribs: DWORD;
pszDestFile: PAnsiChar;
dwDestAttribs: DWORD): UINT;
stdcall;
end;
TpasCopyHooK = class(TComObject,ICopyHookA)
public
function CopyCallback(Hwnd:THandle;
wFunc, wFlags:UINT;
pszSrcFile: PAnsiChar;
dwSrcAttribs: DWORD;
pszDestFile: PAnsiChar;
dwDestAttribs: DWORD): UINT;
stdcall;
end;
//type 多余的type也给去了。

//ICopyHook=ICopyHookA;
//这个真多余。

implementation
function TpasCopyHooK.CopyCallback(Hwnd:THandle;wFunc,wFlags:UINT;
pszSrcFile:PAnsiChar;dwSrcAttribs:DWORD;pszDestFile:PAnsiChar;
dwDestAttribs:DWORD):UINT;stdcall;
var
Msg:string;
MessType:TMsgDlgType;
begin
Application.Handle:=Hwnd;
Msg:='';
MessType:=mtconfirmation;
case wFunc of
FO_COPY:
begin
Msg:=Format('Are yopu sure you want to copy the %s'+
'folder to the %s destination ',[PszSrcFile,pszDestFile]);
end;
FO_DELETE:
begin
Msg:=Format('Are yopu sure you want to del the %s',
[PszSrcFile,pszDestFile]);
end;
end;
if msg<>'' then
result:=messageDlg(Msg,MessType,mbYesNoCancel,0 )
else
result:=id_Yes;
end;

initialization
TComObjectFactory.Create(comserver,TPasCopyHook,CLSID_PascalcopHook,
'PasalCopyHook','CopyHook Demo from Mastering Delphi 3',ciMultiInstance);

end.

 
我已经改对可是不知为什么不起作用啊!
我的.reg文件是
REGEDIT4
[HKEY_CLASSES_ROOT/CLSID/{80A06FA0-7DF2-11D0-98D0-444553540000}]
@="PascalCopyHooK"
[HKEY_CLASSES_ROOT/CLSID/{80A06FA0-7DF2-11D0-98D0-444553540000}/InprocServer32]
@="d://aa.dll"
"ThreadingModel"="Apartment"
[HKEY_CLASSES_ROOT/Directory/shellex/CopyHookHandlers/PCopyHooK]
@="{80A06FA0-7DF2-11D0-98D0-444553540000}"
清高手们再帮忙一下 谢了!
 
程序的功能是在复制和删除文件时给一个提示可是为什么不起做用啊!
 
后退
顶部