Click here to Skip to main content
15,867,704 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,

Small bit of code, Comments tell the story.
Any help would be appreciated as I'm stuck.

C#
void Cbcr_18_PCEQ_SS_control::SlaveCheckin(GUID SlaveGUID)
{
     IUnknown *pUnk;
     void** ppv;

HRESULT hr = GetActiveObject(SlaveGUID, NULL, (IUnknown**)&pUnk); // SlaveGUID is correct,
                                                                  // hr = 0;
hr = pUnk->QueryInterface( IID_IUnknown, (void**)&ppv );          // hr = 0, ppv gets
                                                                  // assigned value
 ppv ->  // IDE does not populate with choices as if it's invalid,
         // or I don't understand what I'm doing.
         // What to do here? The object has a static function I need to call.
Posted
Updated 14-Jun-11 16:22pm
v2

Well, its a void**, of course its not going to get populated. IDEs will not interpret return values. If you want the IDE to populate a pointer, you have to tell it what type of pointer it is.

For example, if you have:
void *myClass;


...and later on you actually get a valid pointer:
((CValidClass *)myClass)->Method();

or...
CValidClass *ptrClass = (CValidClass *) myClass;
ptrClass->Method();
 
Share this answer
 
v2
Comments
Ron Anders 14-Jun-11 12:11pm    
Thank you Albert.

I guess I don't care if the IDE populates. I have used the IDE populating to tell me I'm on the right track. Maybe that's wrong.

I am trying actually to call a static function located in one of three running "Instances" of an object differentiated only by unique GUIDs that
are generated on the fly when each instance is created. Darn, I have this ppv pointer and can figure out how to call my function in an already running
object!.

Thank for your help. :-)

:Ron
You have requested a IUnknown interface (are you sure is what you intended to do?) so you may safely cast ppv to (IUnknown *) and call the available interface methods (QueryInterface, AddRef, Release).
 
Share this answer
 
Comments
Ron Anders 14-Jun-11 11:46am    
CPallini, No I didn't, thank you for the guidance.
With the help of Albert, I now have:

HRESULT hr = GetActiveObject(SlaveGUID, NULL, (IUnknown**)&pUnk); // SlaveGUID is correct,
									  // hr = 0;

hr = pUnk->QueryInterface( IID_IClassFactory, (void**)&ppv );       // hr = 0, ppv gets
Cbcrshimcontrol *ptrClass = (Cbcrshimcontrol *) ppv;		          // address
ptrClass->MidiOutFromMaster((DWORD) 0x27);                            // IDE populating -> with methods including 
   									   //MidiOutFromMaster. Home free? Not so much.
									  // Now some unresolved externals. :-(


MSIL
Creating library .\Debug/bcr_18_PCEQ_SS_control.lib and object .\Debug/bcr_18_PCEQ_SS_control.exp

bcr_18_PCEQ_SS_control.obj : error LNK2028: unresolved token (0A000316) "public: static void __cdecl Cbcrshimcontrol::MidiOutFromMaster(unsigned long)" (?MidiOutFromMaster@Cbcrshimcontrol@@$$FSAXK@Z) referenced in function "public: void __thiscall Cbcr_18_PCEQ_SS_control::SlaveCheckin(struct _GUID)" (?SlaveCheckin@Cbcr_18_PCEQ_SS_control@@$$FQAEXU_GUID@@@Z)

bcr_18_PCEQ_SS_control.obj : error LNK2019: unresolved external symbol "public: static void __cdecl Cbcrshimcontrol::MidiOutFromMaster(unsigned long)" (?MidiOutFromMaster@Cbcrshimcontrol@@$$FSAXK@Z) referenced in function "public: void __thiscall Cbcr_18_PCEQ_SS_control::SlaveCheckin(struct _GUID)" (?SlaveCheckin@Cbcr_18_PCEQ_SS_control@@$$FQAEXU_GUID@@@Z)
 
Share this answer
 
v3
Comments
barneyman 15-Jun-11 3:18am    
eeek!!

no - don't cast from an unk to your class ...

First, you've got to get your overseer to know about the interface you're trying to get to, so import the type library from the slave com object

something like

#import "tlbfile" raw_interfaces_only no_namespace

then you can use CComPtr and CComQIPtr

CComPtr<iunknown> slaveUnk;
GetActiveObject(guid,NULL,&slaveUnk);
CComQIPtr<iyourmidiitf> midiItf(slaveUnk);

then the preproc should get to your methods

(you have to be using ATL for this to work)

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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