Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1825
  • Last Modified:

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
0
PeterLarsen
Asked:
PeterLarsen
  • 7
  • 4
  • 2
  • +2
1 Solution
 
EpsylonCommented:
Use ShellExecute and execute 'Project1 /regserver'.
0
 
CrazyOneCommented:
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
0
 
EpsylonCommented:
You can't register a COM exe with regsvr32. Use something like this:

ShellExecute(Handle, 'open', 'Project1 /regserver' , '', '', sw_hide);
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
CrazyOneCommented:
Oh Ok. Sorry I did not know that. :>)
0
 
PeterLarsenAuthor Commented:
rllibby has posted a comment about this in the old question (http://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
0
 
ziolkoCommented:
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.
0
 
EpsylonCommented:
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.
0
 
ziolkoCommented:
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.
0
 
EpsylonCommented:
Ziolko, tregsvr registers a COM-exe using CreateProcess. So it executes it using the /regserver parameter switch.
0
 
ziolkoCommented:
Epsylon > I didn't look in source code.
0
 
Ten13Commented:
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.
0
 
EpsylonCommented:
Ten13, what the .... are you doing ??????????????????

READ THE QUESTION AND COMMENTS!!!!!!!!!!!!
0
 
EpsylonCommented:
Peter?
0
 
ziolkoCommented:
Dead and not kicking :-(((
ziolko.
0
 
PeterLarsenAuthor Commented:
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
0
 
EpsylonCommented:
> The '/regserver' switch - is that a silent switch

That is correct.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 4
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now