我按照http://www.csdn.net/Develop/Read_Article.asp?Id=6351
《利用Delphi编写IE扩展》写了一个iehelper.dll在开始-运行regsvr32 c:\iehelper.dll
这个程序是正常的,但是我想让我的程序自动注册这个dll
于是我参考了
http://expert.csdn.net/Expert/topic/2331/2331357.xml?temp=.7110254
《如何使程序在运行时自动注册ActiveX控件》
按文章提供代码注册我的dll,为什么总是提示“类名称字符串错误”除了文章所说,还有更好的让程序注册dll的方法么?

解决方案 »

  1.   

    function RegisterOleFile (strOleFileName : STRING; OleAction : boolean ) : BOOLEAN;
    const
      RegisterOle = true;//×¢²á
      UnRegisterOle = false;//жÔØ
    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
            //·µ»Ø×¢²á»òжÔغ¯ÊýµÄÖ¸Õë
            if (OleAction = RegisterOle) then//·µ»Ø×¢²áº¯ÊýµÄÖ¸Õë
               hFunctionAddress := GetProcAddress(hLibraryHandle, pchar('DllRegisterServer'))
               else//·µ»ØжÔغ¯ÊýµÄÖ¸Õë
                   hFunctionAddress := GetProcAddress(hLibraryHandle, pchar('DllUnregisterServer'));
            if (hFunctionAddress <> NIL) then//×&cent;&sup2;á&raquo;ò&ETH;&para;&Ocirc;&Oslash;&ordm;&macr;&Ecirc;&yacute;&acute;&aelig;&Ocirc;&Uacute;
               begin
                 RegFunction := TOleRegisterFunction(hFunctionAddress);//&raquo;&ntilde;&Egrave;&iexcl;&sup2;&Ugrave;×÷&ordm;&macr;&Ecirc;&yacute;&micro;&Auml;&Ouml;&cedil;&Otilde;&euml;
                 if RegFunction >= 0 then //&Ouml;&acute;&ETH;&ETH;×&cent;&sup2;á&raquo;ò&ETH;&para;&Ocirc;&Oslash;&sup2;&Ugrave;×÷&pound;&not;·&micro;&raquo;&Oslash;&Ouml;&micro;>=0±í&Ecirc;&frac34;&Ouml;&acute;&ETH;&ETH;&sup3;&Eacute;&sup1;&brvbar;
                    result := true;
               end;
          finally
            FreeLibrary(hLibraryHandle);//&sup1;&Oslash;±&Otilde;&Ograve;&Ntilde;&acute;ò&iquest;&ordf;&micro;&Auml;OLE/DCOM&Icirc;&Auml;&frac14;&thorn;
          end;
    end;
      

  2.   

    谢谢你了
    我的代码:
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;
    type
     TDllRegisterServer=function:HResult; stdcall;
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
     var
     Ocx:TDllRegisterServer;
     H:THandle;
    begin
      H:=LoadLibrary('c:\iehelper.dll');
     try
       @Ocx:=GetProcAddress(H,'DllRegisterServer');
       Ocx;
     finally
       FreeLibrary(H);
     end;
    end;end.