Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
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
Medium Priority
?
1,823 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
  • 2
  • +2
16 Comments
 
LVL 13

Accepted Solution

by:
Epsylon earned 800 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
Independent Software Vendors: 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!

 
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
 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

722 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