Solved

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

Posted on 2001-07-13
16
1,811 Views
Last Modified: 2012-08-14
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
Comment
Question by:PeterLarsen
  • 7
  • 4
  • 2
  • +2
16 Comments
 
LVL 13

Accepted Solution

by:
Epsylon earned 200 total points
ID: 6281445
Use ShellExecute and execute 'Project1 /regserver'.
0
 
LVL 44

Expert Comment

by:CrazyOne
ID: 6281522
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
 
LVL 13

Expert Comment

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

ShellExecute(Handle, 'open', 'Project1 /regserver' , '', '', sw_hide);
0
 
LVL 44

Expert Comment

by:CrazyOne
ID: 6281590
Oh Ok. Sorry I did not know that. :>)
0
 
LVL 2

Author Comment

by:PeterLarsen
ID: 6281917
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
 
LVL 21

Expert Comment

by:ziolko
ID: 6284659
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
 
LVL 13

Expert Comment

by:Epsylon
ID: 6284867
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
 
LVL 21

Expert Comment

by:ziolko
ID: 6285247
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 13

Expert Comment

by:Epsylon
ID: 6285305
Ziolko, tregsvr registers a COM-exe using CreateProcess. So it executes it using the /regserver parameter switch.
0
 
LVL 21

Expert Comment

by:ziolko
ID: 6285325
Epsylon > I didn't look in source code.
0
 
LVL 2

Expert Comment

by:Ten13
ID: 6285393
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
 
LVL 13

Expert Comment

by:Epsylon
ID: 6285471
Ten13, what the .... are you doing ??????????????????

READ THE QUESTION AND COMMENTS!!!!!!!!!!!!
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6300175
Peter?
0
 
LVL 21

Expert Comment

by:ziolko
ID: 6300971
Dead and not kicking :-(((
ziolko.
0
 
LVL 2

Author Comment

by:PeterLarsen
ID: 6304952
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
 
LVL 13

Expert Comment

by:Epsylon
ID: 6305338
> The '/regserver' switch - is that a silent switch

That is correct.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now