Solved

Work with a COM object using CLSID

Posted on 2002-07-10
8
533 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

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…
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…
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 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

20 Experts available now in Live!

Get 1:1 Help Now