Конференция "Corba" » Add-In к MS Word 2003 [Delphi, Windows]
 
  • CyberPirate (29.08.07 15:37) [0]
    Мои действия.
    1)Создаю ActiveX Library.Сохраняю.
    2)Создаю Automation Object.Под именем DTExtensibility2.
    Ввожу следующий текст:
    [
     uuid(B65AD801-ABAF-11D0-BBBB-00A0C90F2744),
     version(1.0),
     helpstring("Interface for access to MS Office 2003"),
     dual,
     oleautomation
    ]
    interface IDTExtensibility2: IDispatch
    {
     [
     id(0x00000001)
     ]
     HRESULT _stdcall OnConnection([in]  IDispatch * HostApp, [in] long

    ext_ConnectMode, [in]  IDispatch * AddInInst, [in] SAFEARRAY(VARIANT) * custom

    );
     [
     id(0x00000002)
     ]
     HRESULT _stdcall OnDisonnection([in] long ext_DisconnectMode, [in]

    SAFEARRAY(VARIANT) * custom );
     [
     id(0x00000003)
     ]
     HRESULT _stdcall OnAddInsUpdate([in] SAFEARRAY(VARIANT) * custom );
     [
     id(0x00000004)
     ]
     HRESULT _stdcall OnStartupComplete([in] SAFEARRAY(VARIANT) * custom );
     [
     id(0x00000005)
     ]
     HRESULT _stdcall BeginShutdown([in] SAFEARRAY(VARIANT) * custom );
    }
    ;


    Сохраняю.
    3)В процедуре OnConnection пишу ShowMessage('Loaded perfectly...');
    4)Делаю Build проекта.Регистрирую сервер при помоши Run->Register ActiveX Server.Все Ок.
    5)В ветке реестра HKEY_CURRENT_USER\Software\Microsoft\Office\Word\Addins\OfficeAddIn.DTExtensibil ity2 пишу FriendlyName -  Plugin for MS Office 2003
    LoadBehavior - 10(decimal).
    Запускаю Word.

    Ну что не срабатывает? Где ошибка?
    В ворде на вкладке COM-AddIns появляется мой плагин.
    Но когда отмечаю его флажком,ниже в заметках пишет что:
    Not loaded.A runtime error occured during the loading of the COM add-in.

    PS.Delphi 7.0
  • Сергей М. © (29.08.07 15:51) [1]

    > В процедуре OnConnection пишу ShowMessage


    Здесь скрыта как минимум одна из засад - метод не обязан вызываться искл-но в основном треде хост-процесса, в то время как ShowMessage работает только в осн.треде.
  • CyberPirate (29.08.07 16:03) [2]
    Ага...
    Но тем не менее,даже если закоментировать ShowMessage,то все равно сам Word отказывается подключать плагин.Ошибка времени выполнения...
  • Сергей М. © (29.08.07 16:10) [3]
    Показывай текст AX-проекта и текст юнита с автообъектом ..
  • CyberPirate (29.08.07 16:15) [4]
    library WordPlugin;

    uses
     ComServ,
     WordPlugin_TLB in 'WordPlugin_TLB.pas',
     DTExtensibility2 in '..\Class\DTExtensibility2.pas' {DTExtensibility2: CoClass};

    exports
     DllGetClassObject,
     DllCanUnloadNow,
     DllRegisterServer,
     DllUnregisterServer;

    {$R *.TLB}

    {$R *.RES}

    begin
    end.

  • CyberPirate (29.08.07 16:15) [5]
    unit DTExtensibility2;

    {$WARN SYMBOL_PLATFORM OFF}

    interface

    uses
     ComObj, ActiveX, WordPlugin_TLB, StdVcl;

    type
     TDTExtensibility2 = class(TAutoObject, IDTExtensibility2)
     protected
       procedure BeginShutdown(var custom: PSafeArray); safecall;
       procedure OnAddInsUpdate(var custom: PSafeArray); safecall;
       procedure OnConnection(const HostApp: IDispatch; ext_ConnectMode: Integer;
         const AddInInst: IDispatch; var custom: PSafeArray); safecall;
       procedure OnDisonnection(ext_DisconnectMode: Integer;
         var custom: PSafeArray); safecall;
       procedure OnStartupComplete(var custom: PSafeArray); safecall;

     end;

    implementation

    uses ComServ;

    procedure TDTExtensibility2.BeginShutdown(var custom: PSafeArray);
    begin

    end;

    procedure TDTExtensibility2.OnAddInsUpdate(var custom: PSafeArray);
    begin

    end;

    procedure TDTExtensibility2.OnConnection(const HostApp: IDispatch;
     ext_ConnectMode: Integer; const AddInInst: IDispatch;
     var custom: PSafeArray);
    begin

    end;

    procedure TDTExtensibility2.OnDisonnection(ext_DisconnectMode: Integer;
     var custom: PSafeArray);
    begin

    end;

    procedure TDTExtensibility2.OnStartupComplete(var custom: PSafeArray);
    begin

    end;

    initialization
     TAutoObjectFactory.Create(ComServer, TDTExtensibility2, Class_DTExtensibility2,
       ciMultiInstance, tmApartment);
    end.

  • CyberPirate (29.08.07 16:15) [6]
    unit WordPlugin_TLB;

    // ************************************************************************ //
    // WARNING                                                                    
    // -------                                                                    
    // The types declared in this file were generated from data read from a      
    // Type Library. If this type library is explicitly or indirectly (via        
    // another type library referring to this type library) re-imported, or the  
    // 'Refresh' command of the Type Library Editor activated while editing the  
    // Type Library, the contents of this file will be regenerated and all        
    // manual modifications will be lost.                                        
    // ************************************************************************ //

    // PASTLWTR : 1.2
    // File generated on 29.08.2007 17:08:03 from Type Library described below.

    // ************************************************************************  //
    // Type Lib: D:\Projects\COM Add-in\DLL\WordPlugin.tlb (1)
    // LIBID: {1E5CE850-88C7-4447-B6A9-81AD42AF0CD1}
    // LCID: 0
    // Helpfile:
    // HelpString: WordPlugin Library
    // DepndLst:
    //   (1) v2.0 stdole, (C:\WINDOWS\system32\stdole2.tlb)
    //   (2) v4.0 StdVCL, (C:\WINDOWS\system32\stdvcl40.dll)
    // ************************************************************************ //
    {$TYPEDADDRESS OFF} // Unit must be compiled without type-checked pointers.
    {$WARN SYMBOL_PLATFORM OFF}
    {$WRITEABLECONST ON}
    {$VARPROPSETTER ON}
    interface

    uses Windows, ActiveX, Classes, Graphics, StdVCL, Variants;
     

    // *********************************************************************//
    // GUIDS declared in the TypeLibrary. Following prefixes are used:        
    //   Type Libraries     : LIBID_xxxx                                      
    //   CoClasses          : CLASS_xxxx                                      
    //   DISPInterfaces     : DIID_xxxx                                      
    //   Non-DISP interfaces: IID_xxxx                                        
    // *********************************************************************//
    const
     // TypeLibrary Major and minor versions
     WordPluginMajorVersion = 1;
     WordPluginMinorVersion = 0;

     LIBID_WordPlugin: TGUID = '{1E5CE850-88C7-4447-B6A9-81AD42AF0CD1}';

     IID_IDTExtensibility2: TGUID = '{B65AD801-ABAF-11D0-BBBB-00A0C90F2744}';
     CLASS_DTExtensibility2: TGUID = '{D0AD861A-2AEA-41C7-B791-F8128EA37C9D}';
    type

    // *********************************************************************//
    // Forward declaration of types defined in TypeLibrary                    
    // *********************************************************************//
     IDTExtensibility2 = interface;
     IDTExtensibility2Disp = dispinterface;

    // *********************************************************************//
    // Declaration of CoClasses defined in Type Library                      
    // (NOTE: Here we map each CoClass to its Default Interface)              
    // *********************************************************************//
     DTExtensibility2 = IDTExtensibility2;

    // *********************************************************************//
    // Declaration of structures, unions and aliases.                        
    // *********************************************************************//
     PPSafeArray1 = ^PSafeArray; {*}

    // *********************************************************************//
    // Interface: IDTExtensibility2
    // Flags:     (4416) Dual OleAutomation Dispatchable
    // GUID:      {B65AD801-ABAF-11D0-BBBB-00A0C90F2744}
    // *********************************************************************//
     IDTExtensibility2 = interface(IDispatch)
       ['{B65AD801-ABAF-11D0-BBBB-00A0C90F2744}']
       procedure OnConnection(const HostApp: IDispatch; ext_ConnectMode: Integer;
                              const AddInInst: IDispatch; var custom: PSafeArray); safecall;
       procedure OnDisonnection(ext_DisconnectMode: Integer; var custom: PSafeArray); safecall;
       procedure OnAddInsUpdate(var custom: PSafeArray); safecall;
       procedure OnStartupComplete(var custom: PSafeArray); safecall;
       procedure BeginShutdown(var custom: PSafeArray); safecall;
     end;

    // *********************************************************************//
    // DispIntf:  IDTExtensibility2Disp
    // Flags:     (4416) Dual OleAutomation Dispatchable
    // GUID:      {B65AD801-ABAF-11D0-BBBB-00A0C90F2744}
    // *********************************************************************//
     IDTExtensibility2Disp = dispinterface
       ['{B65AD801-ABAF-11D0-BBBB-00A0C90F2744}']
       procedure OnConnection(const HostApp: IDispatch; ext_ConnectMode: Integer;
                              const AddInInst: IDispatch; var custom: {??PSafeArray}OleVariant); dispid 1;
       procedure OnDisonnection(ext_DisconnectMode: Integer; var custom: {??PSafeArray}OleVariant); dispid 2;
       procedure OnAddInsUpdate(var custom: {??PSafeArray}OleVariant); dispid 3;
       procedure OnStartupComplete(var custom: {??PSafeArray}OleVariant); dispid 4;
       procedure BeginShutdown(var custom: {??PSafeArray}OleVariant); dispid 5;
     end;

    // *********************************************************************//
    // The Class CoDTExtensibility2 provides a Create and CreateRemote method to          
    // create instances of the default interface IDTExtensibility2 exposed by              
    // the CoClass DTExtensibility2. The functions are intended to be used by            
    // clients wishing to automate the CoClass objects exposed by the        
    // server of this typelibrary.                                            
    // *********************************************************************//
     CoDTExtensibility2 = class
       class function Create: IDTExtensibility2;
       class function CreateRemote(const MachineName: string): IDTExtensibility2;
     end;

    implementation

    uses ComObj;

    class function CoDTExtensibility2.Create: IDTExtensibility2;
    begin
     Result := CreateComObject(CLASS_DTExtensibility2) as IDTExtensibility2;
    end;

    class function CoDTExtensibility2.CreateRemote(const MachineName: string): IDTExtensibility2;
    begin
     Result := CreateRemoteComObject(MachineName, CLASS_DTExtensibility2) as IDTExtensibility2;
    end;

    end.
  • CyberPirate (29.08.07 16:16) [7]
    В реестре все зарегистрировано.
  • Сергей М. © (29.08.07 16:57) [8]

    > В реестре все зарегистрировано


    Не вижу раздела initialization ..
  • umbra © (29.08.07 17:15) [9]

    > LoadBehavior - 10(decimal).

    а почему такое странное значение? Попробуйте поставить 3
  • Сергей М. © (29.08.07 17:18) [10]
    За каким лешим нужно было набирать IDL-текст "ручками" - ума не приложу)
  • CyberPirate (29.08.07 21:46) [11]

    > Не вижу раздела initialization ..

    Автоматическую регистрацию устрою потом,мне сейчас просто нужно чтоб хоть какие-то наглядные результаты были.
    На данный момент регистрирую через Run->Register ActiveX Server

    > а почему такое странное значение? Попробуйте поставить 3

    Перепутал,это hex значение.Оно эквивалентно 16.

    > За каким лешим нужно было набирать IDL-текст "ручками" -
    >  ума не приложу)

    Это не имеет значения,проблема все равно остается проблемой.
  • Сергей М. © (30.08.07 09:37) [12]

    > CyberPirate   (29.08.07 21:46) [11]


    Покажи все реестровые записи, которые ты получил в рез-те Run->Register ActiveX Server ..
  • CyberPirate (02.09.07 11:47) [13]
    Проблема решена.
  • Corwin (25.09.07 18:47) [14]
    Привет. Поделись, как решил проблему?
 
Конференция "Corba" » Add-In к MS Word 2003 [Delphi, Windows]
Есть новые Нет новых   [120350   +20][b:0][p:0.002]