Click here to Skip to main content
15,885,869 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
God help me if I'm not using the right terms.

I am coding COM server plugins for an app that users load up in that app.
Users can load multiple instances of the same com server plug and they are created via ClassFactory.

I have a need to talk to these plugins from another "overseer" plugin in the same APP's process, so in the Create instance of the plugin as the app is creating instances of it's object I wish to send the resulting created object's pointer to the "overseer" plugin for later calling of this created object's methods, and it's other created instances methods. This works in so much as I am able to send the pointers over to the "overseer" plug and store them away but I have some questions as it's not all going as planned. First he code:

Here is where the object instance is created and a pointer to it (pbcrshimcontrol) assigned.

//////////////////////////////////////////////////////////////////////////////////

C#
HRESULT CbcrshimcontrolFactory::CreateInstance( IUnknown* pUnkOuter, REFIID riid, void** ppv )
{
    AFX_MANAGE_STATE( AfxGetStaticModuleState() );
    // Cannot aggregate.
    if (pUnkOuter != NULL)
        return CLASS_E_NOAGGREGATION;
    // Create component. 
    Cbcrshimcontrol* const pbcrshimcontrol = new Cbcrshimcontrol;


///////////////////////////////////////////////////////////////////////////////////

Here after getting a handle to the "overseer" plugin via standard LoadLibrary() and GetProcAddress() functions (Something I can do as there is only one instance of the "overseer" plugin), I send off the pointer to the newly created object to that "overseer" plugin.

//////////////////////////////////////////////////////////////////////////////////
uReturnVal=lpfnDllFunc1((int const)pbcrshimcontrol);

/////////////////////////////////////////////////////////////////////////////////

The pointers arrive and are called pObject
Now for my questions:

Over at the overseer plugin I have these pointers for each instance of the created plugin as desired. But because (I think), in the "overseer" plug I am in a different namespace, I cannot go: pObject->method. So I need help with that -or-
Maybe I send a pointer to just the method I wish to call but I cant seem to satisfy the VC 2008 compiler in any shape of:

uReturnVal=lpfnDllFunc1((int const)pbcrshimcontrol->method);

Which produces:

cannot convert from 'void (__thiscall Cbcrshimcontrol::* )(DWORD)' to 'int'

Or


uReturnVal=lpfnDllFunc1((int const)pbcrshimcontrol->(DWORD)MidiOutFromMaster);

Which produces:

'->Cbcrshimcontrol::Release' : left operand has '' type, use '.'



What I desire is, on the "overseer" plugin in the different namespace, to type
pObject-> and see all the methods I do over in the proper namespace or at least calling access to just one in particular.

I have been circling this tree barking up it for a couple days now so I need so help

Thanks in advance, I hope I was clear enough.

:Ron
Posted
Updated 10-Jun-11 14:27pm
v2

Not sure I totally follow what you are trying to do, but from what I understand, in the "overseer" you have:
void *pObject; // this actually points to a thingamabob

And what you'd like to do is:
((thingamabob *)pObject)->methodIWantToCall(some_parameter);

But "overseer" is in a different namespace than "thingamabob" right?

Simplest answer is in overseer.h:
#include "thingamabob.h"
((NameSpace::thingamabob *)pObject)->methodIWantToCall(some_parameter);


If you don't want overseer to know anything at all about thingamabob's then you'll have to give overseer a pointer to a function and a pointer to a thingamabob:

void *pObject; // this is some object, don't know what it is
void (*pFunc)(void *pObject, int param1, ...);


In the thingamabob namespace you create a C function (not a member function -- just a standard static C function) that takes a thingamabob and some parameter(s) and in that function you call the thingamabob member function:

void myFunctionForOverseerToCall(void *pObj, int param1)
{
    ((thingamabob *)pObj)->myMemberFunction(param1);
}


Thre is probably another way to do this with a pointer to a member function, but this way makes it pretty obvious what is happening.
 
Share this answer
 
It may be more appropriate to look at using the Running Object Table; register each of the instances in the ROT, then the overseer can query for each of the instances and talk to them thru an admin interface
 
Share this answer
 
Comments
Ron Anders 10-Jun-11 8:32am    
Thank you so very much!

When I compile the "overseer" I get one pesky compiler error
that I can't get rid of.

error C2059: syntax error : ')'

//// On the following line.

((Cbcrshimcontrol::Cbcrshimcontrol*)SlavePtr)->MidiOutFromMaster(MidiMsg);


Where Cbcrshimcontrol is the Thingamabob object, SlavePtr is the address
of Thingamabob that was sent over, MidiOutFromMaster is the static member function to be called, and MidiMsg is the DWORD data to be sent to it.

Again, thank you so much for the help.

:Ron
TRK3 10-Jun-11 12:40pm    
I'm not sure why that doesn't work, but try this instead:

Cbcrshimcontrol::Cbcrshimcontrol *pCtrl = (Cbcrshimcontrol::Cbcrshimcontrol*)SlavePtr;

pCtrl->MidiOutFromMaster(MidiMsg);
Ron Anders 10-Jun-11 14:22pm    
Groveling and down on my face as dead....

That produces:

error C2277: 'Cbcrshimcontrol::{ctor}' : cannot take address of this member function

error C2059: syntax error : ')'

error C2227: left of '->MidiOutFromMaster' must point to class/struct/union/generic type

... Sorry. The syntax of all this baffles me so all I can do is return errors.

Thank you so much for trying to help me.
Ron Anders 13-Jun-11 9:20am    
Well all attepts to access the Slave instances has proved un fruitful very likely due to my lack of experience in this area.

So I took a look at the ROT and early indications are promising. I have issues with System.AccessViolationExceptions accessing my slave from the ROT but will post this in another thread.

Thanks for all the help.

:Ron

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900