Click here to Skip to main content
15,909,953 members
Home / Discussions / COM
   

COM

 
GeneralRe: Drag & Drop Pin
Prakash Nadar27-Nov-03 16:09
Prakash Nadar27-Nov-03 16:09 
GeneralVB COM problem Pin
andyhk9527-Nov-03 15:03
andyhk9527-Nov-03 15:03 
GeneralRe: VB COM problem Pin
Brian Shifrin1-Dec-03 7:07
Brian Shifrin1-Dec-03 7:07 
GeneralRe: VB COM problem Pin
andyhk951-Dec-03 13:39
andyhk951-Dec-03 13:39 
GeneralTOM (Text Object Model) Pin
Andre123427-Nov-03 6:00
Andre123427-Nov-03 6:00 
GeneralThread/ COM Connection point Pin
benglish7225-Nov-03 17:49
benglish7225-Nov-03 17:49 
GeneralProblem solved, thanks! Pin
benglish7225-Nov-03 18:35
benglish7225-Nov-03 18:35 
GeneralProblem with Custom COM object in implementation of Interface Pin
bryces25-Nov-03 16:08
bryces25-Nov-03 16:08 
Hi,

I Have a custom com object which I want to use as a class member for an implemantation of another COM interface.

This is what I have done and the trouble I am having:
I place the COM object (my own one) as a class member in my class that Implements IExtension. (since all my other objects get a reference to the IExtension to see if it is active or not). I have created two functions which preform operations on the Custom COM object.

This is where I come unstuck. I figured I had to QueryInterface to my own implementation of IExtension which has the methods defined. I don't know how to call my custom functions as I get compilation errors saying:

error C2039: 'GetTargetName' : is not a member of '_NoAddRefReleaseOnCComPtr<struct IMyExtension>'
Error executing cl.exe.

I have no idea why this is happening and cannot work out why. If I have defined my extensions and objects as follows....

The only thing I can think of is that I am breaking one of the RULES of COM. I cannot see which one.

Do I have to explicitly define the QI, AddRef, Release methods in my class? From all the example on here... I didn't think I did... here is a reference to an example: http://www.codeproject.com/com/hellocom.asp[^]

your help would be greatly appreciated.

cheers
Bryce





<br />
/////////////////////////////////////////////////////////////////////////////<br />
// CMyExtension<br />
class ATL_NO_VTABLE CMyExtension : <br />
	public CComObjectRootEx<CComSingleThreadModel>,<br />
	public CComCoClass<CMyExtension, &CLSID_MyExtension>,<br />
	public ISupportErrorInfo,<br />
	public IMyExtension,<br />
	public IExtension,<br />
	public IExtensionConfig<br />
{<br />
public:<br />
	CMyExtension()<br />
	{<br />
           //Get the below two constants from the _i.c<br />
           const CLSID CLSID_TargetLayer = {0x2CEBA738,0x0533,0x4F68,{0xB1,0xC5,0x88,0xB3,0xD9,0x5B,0xA3,0xE3}};<br />
           const IID IID_ITargetLayer = {0xD149DEA4,0xBB32,0x4D9A,{0x88,0xC7,0xA2,0x61,0x43,0x7D,0xC8,0xBA}};<br />
<br />
           //create the com<br />
           HRESULT hr = CoCreateInstance(CLSID_TargetLayer, NULL, <br />
                          CLSCTX_INPROC_SERVER,IID_ITargetLayer,<br />
                          (LPVOID*) &m_ipTargetLayer);<br />
           if (SUCCEEDED(hr))<br />
           {<br />
           }<br />
	}<br />
<br />
DECLARE_REGISTRY_RESOURCEID(IDR_MYEXTENSION)<br />
<br />
DECLARE_PROTECT_FINAL_CONSTRUCT()<br />
<br />
BEGIN_COM_MAP(CMyExtension)<br />
	COM_INTERFACE_ENTRY(IHistoryExtension)<br />
	COM_INTERFACE_ENTRY(ISupportErrorInfo)<br />
	COM_INTERFACE_ENTRY(IExtension)<br />
	COM_INTERFACE_ENTRY(IExtensionConfig)<br />
END_COM_MAP()<br />
<br />
BEGIN_CATEGORY_MAP(CMyExtension)<br />
	IMPLEMENTED_CATEGORY( __uuidof(CATID_MxExtension))<br />
END_CATEGORY_MAP()<br />
<br />
// ISupportsErrorInfo<br />
	STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);<br />
<br />
// IHistoryExtension<br />
public:<br />
// IExtension<br />
	STDMETHOD(get_Name)(BSTR * extensionName);<br />
<br />
	STDMETHOD(Startup)(VARIANT * initializationData);<br />
<br />
	STDMETHOD(Shutdown)();<br />
<br />
   // IExtensionConfig<br />
	STDMETHOD(get_ProductName)(BSTR * Name);<br />
	STDMETHOD(get_Description)(BSTR * Description);<br />
	STDMETHOD(get_State)(esriExtensionState * State);<br />
	STDMETHOD(put_State)(esriExtensionState State);<br />
<br />
<br />
  // My methods that deal with custom com object<br />
        HRESULT SetTargetName(BSTR Name);<br />
        HRESULT GetTargetName(BSTR *Name);<br />
<br />
private:<br />
   esriExtensionState m_ExtensionState;<br />
   IApplicationPtr m_ipApp;<br />
   BSTR m_szTargetLayer;<br />
   ITargetLayer *m_ipTargetLayer; //custom com object<br />
};<br />
<br />
<br />
//////////////////////////////////<br />
<br />
//CPP MyHistoryExtension<br />
<br />
//..... removed IExtension and IExtensionConfig methods for easier reading<br />
// Just left functions that deal with custom com object<br />
<br />
HRESULT CMyExtension::SetTargetName(BSTR Name)<br />
{<br />
   return this->m_ipTargetLayer->PutTargetLayerName(Name);<br />
}<br />
<br />
HRESULT CMyExtension::GetTargetName(BSTR *Name)<br />
{<br />
   BSTR tmp;<br />
   HRESULT hr = this->m_ipTargetLayer->GetTargetLayerName(&tmp);<br />
   if(SUCCEEDED(hr)){<br />
      *Name = tmp;<br />
      return S_OK;<br />
   }<br />
<br />
   return E_FAIL;<br />
}<br />
<br />
<br />
////////<br />
// this is an ICommand Implementation.. CPP.<br />
<br />
//I want to get the target layer to see if the Command should be *Enabled<br />
<br />
<br />
STDMETHODIMP CMyCommand::get_Enabled(VARIANT_BOOL * Enabled)<br />
{<br />
   if (Enabled == NULL)<br />
		return E_POINTER;<br />
<br />
   HRESULT hr;<br />
   long selectionCount;<br />
   IExtensionPtr pExtension;<br />
   IExtensionConfigPtr pExtConfig;<br />
   esriExtensionState state;<br />
<br />
   hr =this->m_ipMxDoc->get_FocusMap(&(this->m_ipMap));<br />
   if(FAILED(hr)){return hr;}<br />
   hr = this->m_ipMap->get_SelectionCount(&selectionCount);<br />
   if(FAILED(hr)){return hr;}<br />
<br />
   hr = this->m_ipApp->FindExtensionByName(::SysAllocString(L"My Extension"), &pExtension);<br />
   if(FAILED(hr)){return hr;}<br />
<br />
   pExtConfig = pExtension;<br />
   pExtConfig->get_State(&state);<br />
   if(FAILED(hr)){return hr;}<br />
<br />
<br />
   // ..Problem area .. I Want to QI to my own implementation of IExtension<br />
   CComPtr<IMyExtension> pHistExt;<br />
   const CLSID CLISID_MyExtension = {0x442A8EAF,0x8723,0x4FED,{0xA8,0xA9,0x6D,0x2B,0x65,0x77,0x26,0x61}};<br />
   hr = pExtension->QueryInterface(CLISID_MyExtension, (void **)&pHistExt);<br />
<br />
   CComBSTR szTName;<br />
<br />
   //Compiler BOMBS on this call ....<br />
   //MyCommand.cpp(78) : error C2039: 'GetTargetName' : is not a member of '_NoAddRefReleaseOnCComPtr<struct IMyExtension>'<br />
   hr = pHistExt->GetTargetName(&szTName); //It clearly is a member, as you can see defined above<br />
   if(FAILED(hr)){return hr;}<br />
<br />
   // ..end of problem area<br />
<br />
<br />
   //We need to be find out editing mode<br />
   esriEditState pState;<br />
   hr = this->m_ipEditor->get_EditState(&pState);<br />
   if(FAILED(hr)){return hr;}<br />
<br />
   if(selectionCount>0 && (state == esriESEnabled) && (pState == esriStateEditing) /*&&(layerName != NULL)*/){<br />
      *Enabled = VARIANT_TRUE;<br />
   }else{<br />
      //Set to false, Command is not currently active<br />
      *Enabled = VARIANT_FALSE;<br />
   }<br />
<br />
	return S_OK;<br />
}<br />

Generalworking with New Enum... Pin
rajdawg25-Nov-03 15:09
rajdawg25-Nov-03 15:09 
Generalconstants in IDL file Pin
srikanthos25-Nov-03 1:23
srikanthos25-Nov-03 1:23 
GeneralCEdit in COM Pin
Tomaz Rotovnik24-Nov-03 20:48
Tomaz Rotovnik24-Nov-03 20:48 
GeneralRe: CEdit in COM Pin
Tomaz Rotovnik24-Nov-03 21:02
Tomaz Rotovnik24-Nov-03 21:02 
GeneralRe: CEdit in COM Pin
Tomaz Rotovnik24-Nov-03 22:57
Tomaz Rotovnik24-Nov-03 22:57 
Generalusing serverxmlhttp from a service or existing process Pin
noahsarf24-Nov-03 8:30
noahsarf24-Nov-03 8:30 
GeneralIID_... but no CLSID_... Pin
Xteuk24-Nov-03 4:46
Xteuk24-Nov-03 4:46 
GeneralRe: IID_... but no CLSID_... Pin
Mike Dimmick24-Nov-03 5:31
Mike Dimmick24-Nov-03 5:31 
GeneralRe: IID_... but no CLSID_... Pin
Xteuk24-Nov-03 22:13
Xteuk24-Nov-03 22:13 
GeneralMultiThreaded OutProc Server Pin
TroLoo22-Nov-03 7:22
TroLoo22-Nov-03 7:22 
GeneralRe: MultiThreaded OutProc Server Pin
valikac24-Nov-03 5:49
valikac24-Nov-03 5:49 
Generalneutral threading in XP vs. Win2000 Pin
jremignanti21-Nov-03 11:18
jremignanti21-Nov-03 11:18 
QuestionHow can i change the dllhost appbase??? Pin
Ik@20-Nov-03 23:59
Ik@20-Nov-03 23:59 
QuestionHow do I change the program id within the com project Pin
WoodyMou19-Nov-03 5:21
WoodyMou19-Nov-03 5:21 
AnswerRe: How do I change the program id within the com project Pin
Steve S19-Nov-03 5:44
Steve S19-Nov-03 5:44 
QuestionSame method and property name? Pin
snappa19-Nov-03 2:29
snappa19-Nov-03 2:29 
AnswerRe: Same method and property name? Pin
Vi221-Nov-03 2:31
Vi221-Nov-03 2:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.