Solved

Work with a COM object using CLSID

Posted on 2002-07-10
8
534 Views
Last Modified: 2008-02-01
In my COm object implementation, there is this chunk of code:

initialization
  TAutoObjectFactory.Create(ComServer, TBrowser, Class_Browser, ciInternal, tmApartment);

1. Does an instance of TBrowser is created automatically at the stratup of my application?
2. What if I want to use this instance of the object inside my application and not creating another instance?
3. Can it have something to do with GetActiveOleObject?
0
Comment
Question by:pjroy
8 Comments
 
LVL 26

Expert Comment

by:Russell Libby
ID: 7144694
prjoy,

1.) The code you are describing above does not create an instance of your com class. It creates an instance of a class factory FOR your com class (gets added to the factory list in the ComClassManager.)

2.) See 1

3.) No, GetActiveOleObject (wrapper to GetActiveObject) requires that the COM class be previously registered using RegisterActiveObject.

What is it exactly that you are trying to achieve? Do you only wish one instance of you com class to be loaded by other clients? Or is your application creating an instance of the class, and you wish to get a reference to it?

Russell


0
 

Author Comment

by:pjroy
ID: 7144893
Russell,

Want I want to do is to have only one instance of my COM object. The help you better understand the problem, the application has a Microsoft Money 2002 like GUI. The methods call come from either a JavaScript call through an html pages hosted by TWebBrowser, secondly from the inside of the host (Delphi code). I don't want to write a Delphi object model with a COM wrapper if it is possible for me to build everything into COM object and then using them from JavaScript and Delphi. Remember, its a standalone application and no calls come from the outside. I use window.external in Javascript to access the COM interface exposed by my application.

Thanks

0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 7146174

prjoy,

Is the COM object that your trying to create/share located in your EXE? (Is your app an OLE server). Or is the COM object located in a seperate EXE/DLL?

If in a seperate DLL/EXE, then your host EXE would simply be able to create an instance of the COM object (on startup, or where appropriate). Then when IDocHostUIHandler.GetExternal() gets called, you would pass the reference back to the web browser. This would allow both your host (delphi code) and the web browser script code to access/manipulate the same object.

If your app is an OLE server, which according to your above comment its not (quote: Remember, its a standalone application and no calls come from the outside) then things get a little more interesting. If this is the case, then let me know.

Sorry I can't help more, but it would help if you described where the COM object is located (in your exe, or some other dll/exe)

Russell
 
0
 

Author Comment

by:pjroy
ID: 7146241
The COM is in the same EXE for now. After my project advance, I will possibly refactor and create dll if I need to. What is the difference between those two cases?
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.

 

Author Comment

by:pjroy
ID: 7146253
Sorry, I've written my question before reading your entire answer. I'll increase your point when I'll be back in 2 days and had time to test the concept. Back soon.

Thanks
0
 
LVL 26

Accepted Solution

by:
Russell Libby earned 100 total points
ID: 7146324
prjoy,

Being an OLE server makes a difference, because you may be controlled by another app. The the instancing comes into play (is there already an interface, etc..). Looking at the first comment though:

TAutoObjectFactory.Create(ComServer, TBrowser, Class_Browser, ciInternal, tmApartment);

assures that you will not be. The ciInternal tells delphi NOT to register this class factory with COM, thus no app can get an instance of this interface (other than your own app).

So...
In your app code
1.) in your host, include both the source unit and tlb unit
2.) var (or make property of form, or whatever)
    pbrowser:   IBrowser;
3.) in FormCreate() (or applicable place)
    pbrowser:=TBrowser.Create;
4.) In GetExternal()
    return pbrowser
5.) Your host can also use the pbrowser variable to access the interface (which i assume in turn accesses your application/form/etc...)

Russell



0
 

Expert Comment

by:CleanupPing
ID: 9343076
pjroy:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 5

Expert Comment

by:Lukasz Lach
ID: 9460836
pjroy,
No comment has been added lately (18 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: Award points to rllibby http:#7146324

Please leave any comments here within 7 days.

-- Please DO NOT accept this comment as an answer ! --

Thanks,

anAKiN
EE Cleanup Volunteer
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

Suggested Solutions

Title # Comments Views Activity
Activex loadlibrary and show parented form issue 6 286
TVirtualStringTree  search using TEdit 7 106
Delphi cmd execution 6 55
code issue 8 99
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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 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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

911 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

16 Experts available now in Live!

Get 1:1 Help Now