Solved

Register a Com object

Posted on 2001-07-09
16
449 Views
Last Modified: 2010-04-06
Hi Experts,

I would like to know how to register a com object through another program.
I have notice that a com obejct register itself when activated directly by doubleclick on it.

Regards
Peter
0
Comment
Question by:PeterLarsen
  • 9
  • 3
  • 2
  • +2
16 Comments
 
LVL 26

Accepted Solution

by:
Russell Libby earned 0 total points
ID: 6265447
Peter,

LoadLibrary on the EXE or DLL that contains the COM object and call DLLRegisterServer

Example Code:

type TDLLReg     =  function: Integer; stdcall;
var
   dlr:     TDLLReg;
   hlib:    Integer;


   hLib:=LoadLibrary('x:\exe_or_dll_file.xxx');
   if (hlib <> 0) then
   begin
    @dlr:=GetProcAddress(hLib, 'DllRegisterServer');
    if (@dlr <> nil) then dlr;
    FreeLibrary(hLib);
   end;

Russell
0
 

Expert Comment

by:Buda
ID: 6265967
try

WinExec('regsvr32 C:\ComObjDir\ComObj.xxx /s',0);
0
 
LVL 21

Expert Comment

by:ziolko
ID: 6267776
Also You can search Microsoft's website to find what registry entries must be changed to register COM server. (process of registering COM server is nothiong more than changing registry).
ziolko.
0
 
LVL 2

Author Comment

by:PeterLarsen
ID: 6268273
Hi Russell,

So what you are saying is that my com object has a exported function named 'DLLRegisterServer' - and i should call that ??

Peter

btw - thanks to you all for your comments !!
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 6269517

Hi Peter,

All exe's and dll's that expose COM objects export 4 standard functions:

DllRegisterServer, DllClassObject, DllCanUnloadNow, and DllUnregisterServer

The windows utility regsvr32 is a simple utility that does nothing more than what I described above (load library and call DllRegisterServer or DllUnRegisterServer). I have used this technique in quite a few applications, and it works like a champ.

So to answer your question, yes. Just load the library, make sure you get a valid handle, get the proc address, and call it with the function prototype that i supplied in my previous comment

Russell
0
 
LVL 2

Author Comment

by:PeterLarsen
ID: 6270233
Thanks Rusell
0
 
LVL 2

Author Comment

by:PeterLarsen
ID: 6270241
Btw, The 4 standard functions you'r talking about - that is also what i found in the help file !! :-)
0
 
LVL 2

Author Comment

by:PeterLarsen
ID: 6281029
well, it does not work :-(
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Author Comment

by:PeterLarsen
ID: 6281051
well, it does not work :-(

DllRegisterServer does not exitst in that type of Com Objects.

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

Author Comment

by:PeterLarsen
ID: 6281052
DllRegisterServer does not exitst in that type of Com Objects.

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

Expert Comment

by:modder
ID: 6281271
Hello Peter,

I'm sorry that we can't re-open questions. But here is what I will do.

I will reduce the points on this question to zero. That will refund your points to you.

Then you can post a new question "Follow up".

Just say something like:

"Follow up from http://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20147812

The question was not resolved, and I need further information"

Post the URL of the new question here. That way I will know that you've done it, so I can assume this is resolved, and also the other participants will get a notification and will find the new question easily, so that you can continue there as soon as possible.

Regards

modder
Community Support Moderator@Experts-Exchange
0
 
LVL 3

Expert Comment

by:modder
ID: 6281273
OK. Reduced points to 0.

modder
0
 
LVL 2

Author Comment

by:PeterLarsen
ID: 6281379
Unfortunately the answer didn't help me to solve my problem.
I have posted a new question here :http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=delphi&qid=20150494.

Regards
peter
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 6281572

Sorry Peter,

I had additional notes on OLE Server registration that I should have included as well. What I sent will work for all COM/AX dll's as well as OCX's. For the OLE server portion of it, I clipped the notes from the MSDN:

(in short, winxec(exefile+' /regserver', SW_SHOW))

MSDN:
Self-Registering .EXEs

There isn't an easy way for .EXEs to publish entry points with well-known names, so a direct translation of DllRegisterServer isn't possible. Instead, .EXEs support self-registration using special command line flags. .EXEs that support self-registration must mark their resource fork in the same way as .DLLs, so that the .EXEs support for the command line flags is detectable. Launching an .EXE marked as self-registering with the /REGSERVER command line argument should cause it to do whatever OLE installation is necessary and then exit. The /UNREGSERVER argument is the equivalent to DllUnregisterServer. The /REGSERVER and /UNREGSERVER strings should be treated case-insensitively, and that the character '-' can be substituted for '/'.

Other than guaranteeing that it has the correct entry point or implements the correct command line argument, an application that indicates it is self-registering must build its registration logic so that it may be called any number of times on a given system even if it is already installed. Telling it to register itself more than once should not have any negative side effects. The same is true for unregistering.

On normal startup (without the /REGSERVER command line option) .EXEs should call the registration code to make sure their registry information is current. .EXEs will indicate the failure or success of the self-registration process through their return code by returning zero for success and non-zero for failure.

Russell
0
 
LVL 2

Author Comment

by:PeterLarsen
ID: 6355376
Thanks rllibby - this works.

"if ShellExecute(self.Handle, 'open' ,PChar(ComObjectName) ,Pchar('/regserver') ,nil ,sw_hide) <= 32 then ..."

Regards
Peter
0
 
LVL 2

Author Comment

by:PeterLarsen
ID: 6367019
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

910 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

22 Experts available now in Live!

Get 1:1 Help Now