• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 553
  • Last Modified:

Work with a COM object using CLSID

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
pjroy
Asked:
pjroy
1 Solution
 
Russell LibbySoftware Engineer, Advisory Commented:
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
 
pjroyAuthor Commented:
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
 
Russell LibbySoftware Engineer, Advisory Commented:

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
Technology Partners: 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!

 
pjroyAuthor Commented:
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
 
pjroyAuthor Commented:
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
 
Russell LibbySoftware Engineer, Advisory Commented:
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
 
CleanupPingCommented:
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
 
Lukasz LachCommented:
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

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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now