views:

172

answers:

2

This is really a follow on question to a previous one, where I need to register applications, TLBs and OCXs per user, rather than into HKLM. I have written the following code - based on answers here and elsewhere, BUT the TLB is not registered - no error is thrown, just nothing happens (this code snippet comes from the Embarcadero website.

procedure RegisterTypeLibrary(TypeLib: ITypeLib; const ModuleName: string);
var
  Name: WideString;
  HelpPath: WideString;
  RegisterTypeLibForUser : function(tlib: ITypeLib; szFullPath, szHelpDir: POleStr): HResult; stdcall;
  res : HResult;
begin
  Name := ModuleName;
  HelpPath := ExtractFilePath(ModuleName);
  res:=RegisterTypeLib(TypeLib, PWideChar(Name), PWideChar(HelpPath));
  if res <> S_OK then begin
    @RegisterTypeLibForUser:=GetProcAddress(GetModuleHandle('oleaut32.dll'), 'RegisterTypeLibForUser');
    if (@RegisterTypeLibForUser <> nil) then begin
      res:=RegisterTypeLibForUser(TypeLib, PWideChar(Name), PWideChar(HelpPath));
    end;
  end;
  //MessageBox(GetForegroundWindow, PChar(IntToHex(res, 8)), nil, MB_OK);
  OleCheck(res);
end;

Anyone got any pointers as I am now lost.

Update :

Thanks for all the help and suggestions, so to clarify ...

As I understand that it, I shouldn't require elevated permission, and so this should to be working, but I could be wrong. Application isn't virtualized (or at least it isn't meant to be), at the moment it just calls the above code, and nothing else.

If I run it as admin it works (or at least doesn't throw an error), not elevating it gives me an error. So can I just not do this at all, or am I doing it wrong? This is the same as when I register it via regsvr32, although that is a slightly different question - how to do the same, but for OCX controls.

+1  A: 

You still need to setup the reg keys as shown in the QC (your link) but this time in the current user registry.

ChristianWimmer
You mean change and recompile the VCL - or can it be done as local copies of the files do you think ?
Mmarquee
No, I mean you need to register your COM Class in the registry. RegisterTypeLib does not create reg keys for your CoClasses in CLSID.
ChristianWimmer
A: 

You also have to run with elevated privileges when running against Vista or Win7.

-EDIT-
The problem could be that your application is being virtualized and the initial call to RegisterTypeLib IS returning OK, but its only valid for the current session. Either eliminate that call completely, or only perform the call if your running on an OS version prior to vista.

skamradt
It is intended to work without Admin rights since the function access only HKCU hive.
ChristianWimmer