Newsgroup: it.comp.programmare.win32
Titolo: [Shell] Perchè mi va in crash??

Salve a tutti!
Finalmente sono riuscito a trovare un esempio di property sheet shell
extension.. ma crasha! e non riesco a capire perchč... c'č qualcuno che mi
puo' aiutare? O che cmq sa indicarmi come effetture il debug di una shell
extension come questa?
P.S.: scusate i vari file:// sparsi per il codice.. č colpa di questo
maledetto outlook...
Grazie 1000
 |-.-.-.-.-.-.-. CODE .-.-.-.-.-.-.-.-.-.|
 unit Shell;
        interface
        uses
            Windows, Messages, ComObj, CommCtrl,ComServ, ShlObj, ActiveX,
 ShellApi;
            //, SysUtils, Forms, Dialogs;
        Const
          CLSID_PropertySheetShellExtension: TGUID=(D1:$C8051380; D2:$7FF4;
 D3:$11D3; D4:($AD,$1E,$E5,$28,$CE,$07,$7C,$79));
        type
            TPropertySheet = class(TComObject, IShellExtInit,
 IShellPropSheetExt)
            private
              szFile: array[0..MAX_PATH] of Char;
            public
              function Initialize(pidlFolder: PItemIDList; lpdobj:
 IDataObject;
               hKeyProgID: HKEY): HResult; stdcall;
             function AddPages(lpfnAddPage: TFNAddPropSheetPage; lParam:
 LPARAM):
        HResult; stdcall;
                  function ReplacePage(uPageID: UINT; lpfnReplaceWith:
        TFNAddPropSheetPage;
               lParam: LPARAM): HResult; stdcall;
        End;
        implementation
 {$R DIALOG.RES}
 //   const ID_EDIT1 = 101;edit control in dialog resource
    function DialogProc(hwndDlg : HWND;Msg : Cardinal;wParam :
Longint;lParam
 :
    LongInt) : BOOL; stdcall;
    begin
      Result := True;
      case Msg of
        WM_INITDIALOG : begin
         // Set file name in edit control
file://SetDlgItemText(hwndDlg,ID_EDIT1,PChar(PPropSheetPage(lParam).lParam))
;
          Result := False; file://We will set the focus
                         end;
        WM_DESTROY :begin
                    End; file://destroying the page
        WM_COMMAND :Begin
                    End; file://handle commands from dialog controls
        WM_NOTIFY : Begin
                      file://PNMHDR(lParam)^.code;
                    End;
        else  Result :=False; file://default return value for unhandled
 messages
      end;
    messagebox(null,'DialogProc section','Debug Message',MB_OK);
    end;
        function TPropertySheet.Initialize(pidlFolder: PItemIDList; lpdobj:
        IDataObject;hKeyProgID: HKEY): HResult;
        var medium: TStgMedium;
        var fe: TFormatEtc;
        begin
          file://Retrieve the filename. Code borrowed from ConextM.pas in D3
 Demos\ShellExt
          // Fail the call if lpdobj is Nil.
          with fe do
          begin
            cfFormat := CF_HDROP;
            ptd := Nil;
            dwAspect := DVASPECT_CONTENT;
            lindex := -1;
            tymed := TYMED_HGLOBAL;
          end;
          // Fail the call if lpdobj is Nil.
          if lpdobj = Nil then
          begin
            Result := E_FAIL;
            Exit;
          end;
          // Render the data referenced by the IDataObject pointer to an
 HGLOBAL
          // storage medium in CF_HDROP format.
          Result := lpdobj.GetData(fe, medium);
          if Failed(Result) then Exit;
          // If only one file is selected, retrieve the file name and store
 it in
          // szFile. Otherwise fail the call.
          if DragQueryFile(medium.hGlobal, $FFFFFFFF, Nil, 0) = 1 then
          begin
            DragQueryFile(medium.hGlobal, 0, szFile, SizeOf(szFile));
            Result := NOERROR;
          end else Result := E_FAIL;
          ReleaseStgMedium(medium);
          messagebox(null,'Initialize section','Debug Message',MB_OK);
        end;
        function TPropertySheet.AddPages(lpfnAddPage: TFNAddPropSheetPage;
 lParam:
        LPARAM): HResult; stdcall;
        var psp : TPropSheetPage;
        var hpage : HPropSheetPage;
        begin
           file://code here if adding new property sheet pages
           FillChar(psp,SizeOf(psp),0);
           psp.dwSize := sizeof(psp); // no extra data
           psp.dwFlags := PSP_USEREFPARENT;//set only title
           psp.hInstance := HInstance;
 //          Messagebox(null,'Debug message - Prima Di Intresource','Debug
 Message',MB_OK);
           psp.pszTemplate :=MakeIntResource('PAGEDLG');
 //          Messagebox(null,'Debug message - Dopo Di Intresource','Debug
 Message',MB_OK);
           psp.pcRefParent := @RefCount;
           psp.pfnDlgProc := @DialogProc;
           psp.pszTitle := 'Pagina Aggiunta';
   //        psp.lParam := Integer(@szFile); file://pass file name as param
           hpage := CreatePropertySheetPage(psp);
           if hpage <> nil then
           begin
              if (lpfnAddPage(hpage, lParam) = False) then
                  begin
                   DestroyPropertySheetPage(hpage);
                   Result := NOERROR;
                  end
                  else
                     DestroyPropertySheetPage(hpage);
 //                  Result := HTERROR;
           End;
        End;
        function TPropertySheet.ReplacePage(uPageID: UINT; lpfnReplaceWith:
        TFNAddPropSheetPage;
               lParam: LPARAM): HResult; stdcall;
        begin
          file://code here if replacing any property sheet pages
          Result := NOERROR;
        end;
        initialization
        TComObjectFactory.Create(ComServer,
 TPropertySheet,CLSID_PropertySheetShellExtension,'', 'PropertySheet
 Example', ciMultiInstance);
 //       messagebox(NULL,'TcomObject Factory Section','Debug
 Message',MB_OK);
        end.
 --
 /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
 |()|===================|()|
 |()|                                           |()|
 |()|        .-=] ExTrEmE [=-.      |()|
 |()|                                           |()|
 |()|          ICQ#12987528        |()|
 |()|   MailTo : 
extr...@tin.it
  |()|
 |()|                                           |()|
 |()|===================|()|
 \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Ho risolto il problema del crash.. ma ora viene aggiunta la pagina delle
proprietą.. ma quando ci clikko me la toglie.. credo faccia l'unload della
dll.. ma non so' da che parte cominciare...
Ecco il codice...

{$R MYDIALOG.RES}
 //  const ID_EDIT1 = 105; // edit control in dialog resource
   function DialogProc(hwndDlg : HWND;Msg : Cardinal;wParam : Longint;lParam
:LongInt) : BOOL; stdcall;
   begin
     Result := True;
     case Msg of
       WM_INITDIALOG : begin
        // Set file name in edit control
 //
SetDlgItemText(hwndDlg,ID_EDIT1,PChar(PPropSheetPage(lParam).lParam));
         Result := False; // We will set the focus
                        end;
       WM_DESTROY :begin
                   End; // destroying the page
       WM_COMMAND :Begin
                   End; // handle commands from dialog controls
       WM_NOTIFY : Begin
                   End;
       else  Result :=False; // default return value for unhandled messages
     end;
   end;
       function TPropertySheet.Initialize(pidlFolder: PItemIDList;
lpdobj:IDataObject;hKeyProgID: HKEY): HResult;
       var medium: TStgMedium;
       var fe: TFormatEtc;
       begin
         // Retrieve the filename. Code borrowed from ConextM.pas in D3

       end;
       function TPropertySheet.AddPages(lpfnAddPage: TFNAddPropSheetPage;
lParam:
       LPARAM): HResult; stdcall;
       var psp : TPropSheetPage;
       var hpage : HPropSheetPage;
       begin
          // code here if adding new property sheet pages
          FillChar(psp,SizeOf(psp),0);
          psp.dwSize := sizeof(psp); // no extra data
          psp.dwFlags := PSP_USETITLE+PSP_USEREFPARENT; // set only title
          psp.hInstance := HInstance;
          psp.pszTemplate :=MakeIntResource('PAGEDIALOG');
          psp.pcRefParent := @RefCount;
          psp.pfnDlgProc := @DialogProc;
          psp.pszTitle := '..-=] ExTrEmE [=-..';
          psp.lParam := Integer(@szFile); // pass file name as param
          hpage := CreatePropertySheetPage(psp);
          if hpage <> nil then
          begin
             if ((lpfnAddPage(hpage, lParam))=False) then
                 begin
                  messagebox(HInstance,'Debug - Check 01','Debug
Message',MB_OK+MB_SYSTEMMODAL);
                  DestroyPropertySheetPage(hpage);
                  Result := NOERROR;
                 end
                 else
                  begin
                   messagebox(HInstance,'Debug - Check 02','Debug
Message',MB_OK+MB_SYSTEMMODAL);
                   DestroyPropertySheetPage(hpage);
                   Result := ERROR;
                   end;
          End;
       End;
       function TPropertySheet.ReplacePage(uPageID: UINT; lpfnReplaceWith:
       TFNAddPropSheetPage;
              lParam: LPARAM): HResult; stdcall;
       begin
         // code here if replacing any property sheet pages
         Result := NOERROR;
       end;
       initialization
       TComObjectFactory.Create(ComServer,
TPropertySheet,CLSID_PropertySheetShellExtension,'', 'PropertySheet
Example', ciMultiInstance);
       end.