question

youqiangwu-6561 avatar image
0 Votes"
youqiangwu-6561 asked RLWA32-6355 commented

How to create components with caller information


Currently app_a creates instance app_b by using CoCreateInstance, but how does app_b know which app created it?


Is there a function equivalent to CoCreateInstance and can pass input parameters?

c++windows-api-general
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RLWA32-6355 avatar image
0 Votes"
RLWA32-6355 answered RLWA32-6355 commented

As previously suggested, you can use the MFC support for Automation to add a COM object to your server with an interface that can be used for customization information passed by the calling client. Client applications call CoCreateInstance and request the customization interface. The COM runtime will start the server process and it can be configured through the customization interface BEFORE any documents have been opened.

· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks a lot again

it is relatively late to call the customization interface after Client applications call CoCreateInstance;

According to the previous statement, there is currently no way to identify it when the server is instantiated?

0 Votes 0 ·

Well, a successful call to CoCreateInterface by a COM client means that the out-of-process server is running. Just saying that this is "relatively late"regarding customization doesn't explain what you want to achieve.

If being able to communicate with a COM server before a document is opened doesn't meet your needs then perhaps you should consider some other form of inter-process communication between the server and clients (e.g., pipes, etc.).


0 Votes 0 ·

ok, that means:
there is no way to process some customized processes when the server instance is starting

as for communicating between the server and clients through other methods,
it feels relatively late ; after all, the server has been started;

Let me see if the customized implementation can be delayed

Thanks again for your patient reply

0 Votes 0 ·
Show more comments
RLWA32-6355 avatar image
0 Votes"
RLWA32-6355 answered youqiangwu-6561 edited

Short answer is no.

Now for the long answer -

First, its important to understand that when app_a calls CoCreateInstance that it does not directly create an instance of app_b (out-of-process COM server). Rather, it is the COM runtime that instantiates app_b. If you use process explorer to examine the process tree you can see that app_a is NOT the parent process of app_b.

Also, since a running COM Server can service more than one client, it is common that after app_b (the COM server) begins running to service app_a the same instance of app_b will also service app_c, app_d, etc. when they call CoCreateInstance. So although there can be multiple COM client processes, only one COM server process will be running.

After a successful call to CoCreateInstance the client process will have an interface pointer for the instantiated COM object hosted by the server. Assuming that you are the author of the COM Server you can write an interface method that clients can call to pass data to the server. Generally, a running out-of-process COM Server is capable of identifying the process associated with an incoming call.

· 7
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

thanks for you reply.
First, we need to know who created the local instance app_b when it was created by CoCreateInstance;
instead of interacting through the interface after the instance is started

Second, since a running COM Server can service more than one client, how to do it?
now we are dealing with it like this currently
1. client(app_a) : CoCreateInstance
2. server(app_b): CoRegisterClassObject
3. show app_b


Looking forward to your reply



0 Votes 0 ·

You've just reworded the original question, but my answer remains the same.

COM does not provide a server with the identity of the process that called CoCreateInstance. The only thing that COM does is to provide a parameter on the command line that is passed to the server process when it is started so that it can tell that it was started by the COM runtime.

Why does your COM server need to know the identity of the processes that call CoCreateInstance?

0 Votes 0 ·

thanks!

The scene is as follows:
1. client(app_a) : CoCreateInstance
1.1 start app_b, we create a OleTemplateServer and associate with document template(doc-frame-view);
1.2 CoRegisterClassObject
1.3 create doc template

  1. since a running COM Server can service more than one client (app_a or app_c)
    The server's processing flow for different clients is inconsistent,and the timing of this process is before step 1.3

so we need to konw the iendtity of the processes that call CoCreateInstance?


since COM does to provide a parameter on the command line that is passed to the server process

Can we add additional parameters ?



0 Votes 0 ·
Show more comments