Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Registring COM objects at runtime

Posted on 2000-05-03
12
Medium Priority
?
311 Views
Last Modified: 2010-04-04
Greetings,

COM objects are usually registered using regsvr32.exe or such like. Is there any way of registering them programmatically. In other words if an application uses a COM object and it is not registered, the application must be able register it.

My questions are:

1) How can I determine if my COM object is registered

2) How can I register a COM object at run time

Thanks,

Robert Lancaster
 
0
Comment
Question by:RLancaster
  • 3
  • 2
  • 2
  • +5
12 Comments
 
LVL 10

Expert Comment

by:Lischke
ID: 2772572
Hi Robert,

actually, regsvr32 also registers a COM object at runtime. It loads the DLL into memory and calls its DLLRegisterServer. This in turn triggers the ComServer instance to call the registration procedure of an eventual type lib and all COM factories of the DLL/application. Of course you can do this too.


1) Examine the registry for the 'CLSID\' + ClassID key for your COM object.

2) Call DLLRegisterServer of your DLL (do a LoadLibrary and a GetProcAddress).

Ciao, Mike
0
 
LVL 2

Expert Comment

by:hubdog
ID: 2772592
uses OLEctl,....
var
OCXHand: THandle;
RegFunc: TDllRegisterServer;
begin
OCXHand:= LoadLibrary('c:\windows\system\your.dll');//or your.ocx
RegFunc:= GetProcAddress(OCXHand, 'DllRegisterServer');
if RegFunc <> 0 then ShowMessage('Error!');
FreeLibrary(OCXHand);
end;
0
 
LVL 2

Expert Comment

by:mullet_attack
ID: 2772870
if your com server is an EXE server, simply run it with /register in the command line.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 3

Expert Comment

by:shenqw
ID: 2773270
Tregsvr source code @  $(delphi)\Demos\Activex\Tregsvr (D5)
0
 
LVL 1

Expert Comment

by:tomer_engel
ID: 2774869
ok lets get some things stright:

1)if you're writing the server you sould implement some basic function in the server--if that's the case contact me again i'll help ya.

2)to check if the server is registered check out the registry using the regedit.exe located in the windows\system under HKEY_CLASSES_ROOT\CLSID and see if the server is  regutered, if you don't know the class id then ask i'll tell you how to figure it out.

3)if you hadn't wirtten it use the regsvr32.exe :beacuse every exe server is supplied(/or created if you create the file) with a dll that supplies the stub and the proxy servises,, this is what should be registered, lets say the dll is mydllServer.dll
write this line down(in the dos prompt or in a batch file )

regsvr32 -s mydllServer.dll
(to find out about more of the regsvr.exe switches just enter regsvr/? in the dos prompt.

as i said you can supply you're server with a bacth file (a file with a .bat extention) that only have the reigistration line as above

if you have more questions;ask

Tomer
 
0
 
LVL 1

Expert Comment

by:tomer_engel
ID: 2774994
forgot somehitng:

you asked about runtime ,so add this code where you want to check if the server s regitered(and add the Registry and the ShellAPI packages in the uses cluase)

var
  r:Tregistry;
..
..
..
begin
..
..

r:= TRegistry.create(HKEY_CLASSES_ROOT);
try
 r.OpenKey('CLSID',False);
//check to see if the server is registered
 if  r.ReadString('the CLSID of the component here') = ''
   then//class not regitered--run the batch file
     shellexecute( handle,PChar('OPEN'),PChar('your bacth file here'),PChar(''),PChar('the dirctory to the file here'),SW_MINIMIZE);
finally
 r.free;end;//the try->finally

the bacth file is the bacth file you prepered earilear(or try insted of the bacth file in the Shellexecute to, put the regsvr32.exe,, i didn't have time to try it out (sorry)


0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2775191
Listening
0
 
LVL 1

Expert Comment

by:xsoft
ID: 2775621
listening...
0
 
LVL 1

Author Comment

by:RLancaster
ID: 2776443
instead of using the batch file could you use the piece of code offered b hubdog near the top of this question ?

things are looking up though !!!
0
 
LVL 10

Accepted Solution

by:
Lischke earned 800 total points
ID: 2776755
Hi Robert, fine that you listen again. We have been discussing your question meanwhile without you.

Unfortunately, I'm not sure what you really want. Is it the information? I believe not, because this has been given yesterday by me just a couple of minutes after you asked. So it is the code you are after, right? Although, also here I have doubts since you have not mentioned this fact anywhere. Actually, now three people are here saying all the same with different words and, I believe, the one with the most words issued will win.

Ok, then here are my words again accompanied with code:

1) Examine the registry for the 'CLSID\' + ClassID key for your COM object.

function IsClassRegistered(GUID: TGUID): Boolean;

var
  ClassID: String;

begin
  with TRegistry.Create do
  try
    ClassID := GUIDToString(GUID);
    RootKey := HKEY_CLASSES_ROOT;

    Result := OpenKey('\CLSID\' + ClassID, False);
  finally
    Free;
  end;
end;


2) Call DLLRegisterServer of your DLL (do a LoadLibrary and a GetProcAddress).


procedure RegisterCOMServer(DLLName: String);

var
  DLLHandle: THandle;
  RegFunc: TDllRegisterServer;

begin
  DLLHandle := LoadLibrary(DLLName);
  if Handle <> 0 then
  begin
    RegFunc := GetProcAddress(Handle, 'DllRegisterServer');
    if Assigned(RegFunc) then RegFunc;
    FreeLibrary(DLLHandle);
  end
  else RaiseLastWin32Error;
end;

Ciao, Mike
0
 
LVL 1

Author Comment

by:RLancaster
ID: 2866575
Comment accepted as answer
0
 
LVL 1

Author Comment

by:RLancaster
ID: 2866576
Sorry for taking to long to respond !!! It works like a dream.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses
Course of the Month14 days, 6 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question