Link to home
Start Free TrialLog in
Avatar of PeterLarsen
PeterLarsen

asked on

Register Com Object - follow up from http://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20147812

Hi Experts,

I would like to know how to register a com object through another program.

This is what i have :

1: Create 'New Application'
2: Hit New - ActiveX tab and selecting 'Com Object'.

This create a com object as a exe file.

When i want to use this com-exe file from within another application the com object is unknown to windows.

To make the com-exe file known to windows i have to activate the com-exe file once.
After this the com object is known to windows and may be activated from other applications.

My question is - How do i make the com object visible to other applications without having to activate
the com object first ??

Regards
Peter
ASKER CERTIFIED SOLUTION
Avatar of Epsylon
Epsylon

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Here is how I register these things to the system.

ShellExecute(Handle, 'OPEN', PChar('REGSVR32.exe') , PChar(TheFile), '', sw_normal);

Now I know of three possible messages...there may be more...that will return in a message box and I have not figured out quite how to trap for these messages and then us ones that I have designed. But this does work or at least it has for me. :>)


The Crazy One
Avatar of Epsylon
Epsylon

You can't register a COM exe with regsvr32. Use something like this:

ShellExecute(Handle, 'open', 'Project1 /regserver' , '', '', sw_hide);
Oh Ok. Sorry I did not know that. :>)
Avatar of PeterLarsen

ASKER

rllibby has posted a comment about this in the old question (https://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=delphi&qid=20147812) - dated 07/13/2001 11:58AM PST .

Could i have your comment on this, please.

Thanks
Peter
Avatar of Lukasz Zielinski
Peter > once again. Search Microsoft's web site to find what registry entries must be done to register COM server, registering COM/DCOM servers is nothing more than changeing registry.
Epsylon & CrazyOne > use tregsvr.exe instead regsvr32.exe
easier to use and runs only in commandtext mode which means no dialog boxes.
ziolko.
Peter, what should I comment on that? It's a fact.

Ziolko, we are talking about an exe here. It has no exported functions (entry points) like a dll. That's why it has the /regserver and /unregserver parameter switches. The only way to register an exe is by running it. To do that silently use the /regserver switch.
Epsylon > if you want register COM/DCOM server by changeing registry entries it makes no difference if it is DLL or EXE same thing for tregsvr, even more with tregsvr You can register COM/DCOM object with only .TLB file (simlpe add -t switch)
ziolko.
Ziolko, tregsvr registers a COM-exe using CreateProcess. So it executes it using the /regserver parameter switch.
Epsylon > I didn't look in source code.
Hi Peter

Hang on here!
The thing is - as you allready know - that you have to register your COM object with Windows for other programs to be able "to see" and use the object.

There are a lot of diferent ways to register your COM object. But it all comes down to some entries added to the registry. Delphi has some helper rutines to do this for you. DllRegisterServer and DllUnregeisterServer.

At the end I have posted the source from at project that will actually help you carry out some of the suggestions in this thread. Notice that it is not possible to register your COM object by using LoadLibrary as suggested in the thread you reffered to. It is possible to add this to your project source
    program Project1;
    uses ComServ;
    exports
      DllGetClassObject,
      DllCanUnloadNow,
      DllRegisterServer,
      DllUnregisterServer;
    ... (rest of the source)
and call DllRegisterServer by LoadLibrary and GetProcAddress. However things are not initialized right so you will get an access violation.

Well back to problem in hand! During installation of your program (or just the COM object) you must call "project1.exe /regserver" using ShellExecute or what ever suits you best (might even be from within you installation program).

You could add the registry entries manually. Open the registry (regedit.exe - like you didn't know that :o) and navigate down to "HKEY_CLASSES_ROOT\CLSID\{CLASS ID OF YOUR COM}" and be inspired!

So now there's only one thing left. The source!

Good luck

Martin

program Project1;

uses
  ComServ, // Add this...
  Dialogs,
  Forms,
  COMObj,
  Unit1 in 'Unit1.pas' {Form1},
  Project1_TLB in 'Project1_TLB.pas',
  Unit2 in 'Unit2.pas' {COMTest: CoClass};

{$R *.TLB}
{$R *.res}

begin
// ...not forgetting this...
  if ParamStr(1) = '/regserver' then begin
    DllRegisterServer;
    Exit;
  end;
  if ParamStr(1) = '/unregserver' then begin
    DllUnregisterServer;
    Exit;
  end;
// ...and now you're done!



  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.
Ten13, what the .... are you doing ??????????????????

READ THE QUESTION AND COMMENTS!!!!!!!!!!!!
Peter?
Dead and not kicking :-(((
ziolko.
I'm out of office for vacation and will not return until the beginning of august. I have not read your comments  before now. For that i apologize.

I dont think Ten13 proposed answer help me much.
I my com-exe had the function 'DllRegisterServer' i would use 'LoadLibrary' etc.

The '/regserver' switch - is that a silent switch or do i have to capture it similar to what Ten13 propose ??

Regards
Peter
> The '/regserver' switch - is that a silent switch

That is correct.