if (hFunctionAddress <> nil) then //判断注册或卸载函数是否存在
    begin
      RegFunction := TOleRegisterFunction(hFunctionAddress); //获取操作函数的指针
      if RegFunction >=0 then  //执行注册或卸载操作,返回值>=0表示执行成功
        Result := True;
    end;
程序运行时,RegFunction始终是小于0,TOleRegisterFunction(hFunctionAddress); 应该返回大于0的数。为什么呀?请指教。源程序在:http://www.pengye.com.cn/gd/temp/tem.rar
D7下编译通过。

解决方案 »

  1.   

    if (hFunctionAddress <> nil) then //判断注册或卸载函数是否存在
        begin
          RegFunction := TOleRegisterFunction(hFunctionAddress); //获取操作函数的指针
          if RegFunction <0 then 
            Result := False
          else
            Result:=True;
        end;楼主不妨按一种思维,从反面入手,看可不可以解决问题所在
      

  2.   

    type
      TOleRegisterFunction = function : HResult;//注册或卸载函数的原型var
      hFunctionAddress : TFarProc;  //DLL或OCX中的函数句柄,由GetProcAddress返回
      RegFunction : TOleRegisterFunction;  //注册或卸载函数指针
    begin
      ...
        hFunctionAddress := GetProcAddress(hLibraryHandle, pchar('DllRegisterServer'))
        if (hFunctionAddress <> nil) then //判断注册或卸载函数是否存在
        begin
          RegFunction := TOleRegisterFunction(hFunctionAddress); //获取操作函数的指针
          if RegFunction >=0 then  //执行注册或卸载操作,返回值>=0表示执行成功
            Result := True;
        end;  
      ...
    end;===============================
    从反正找原因,确实是一个负数。
    if RegFunction >=0 then  是不是真的执行了函数?并且这段代码是网上所公认的代码,为什么我这里返回始终是一个负数?
      

  3.   

    谢谢 xinaideren2002(心灯) ( )  的关注。