Click here to Skip to main content
15,885,767 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Help - Grid and recursive function Pin
CPallini26-Feb-15 20:27
mveCPallini26-Feb-15 20:27 
GeneralRe: Help - Grid and recursive function Pin
Member 1148392226-Feb-15 20:31
Member 1148392226-Feb-15 20:31 
GeneralRe: Help - Grid and recursive function Pin
CPallini26-Feb-15 21:51
mveCPallini26-Feb-15 21:51 
AnswerRe: Help - Grid and recursive function Pin
Richard MacCutchan26-Feb-15 21:28
mveRichard MacCutchan26-Feb-15 21:28 
AnswerRe: Help - Grid and recursive function Pin
seemajoshii27-Feb-15 1:21
seemajoshii27-Feb-15 1:21 
QuestionRe: Help - Grid and recursive function Pin
David Crow27-Feb-15 3:45
David Crow27-Feb-15 3:45 
AnswerRe: Help - Grid and recursive function Pin
Member 1148392227-Feb-15 7:12
Member 1148392227-Feb-15 7:12 
Questionhow to create a com class template and use if for CoCreateInstance? Pin
ehaerim26-Feb-15 9:06
ehaerim26-Feb-15 9:06 
I have a need for creating a class template and you may help me.

[1] Multiple coclasses will be implemented in a single dll.
[2] Each coclass will implement the same interfaces but will have different class/clsid/resid.
[3] It is necessary to create a class template taking clsid/resid as its template paramemters.
[4] Finally, I need to use template classes for CoCreateInstance.

Let me elaborate more in detail.

Here is a simple interface IA defined.

interface IA : IDispatch
{
[id(1), helpstring("method M1")] HRESULT M1();
};


Below ia a coclass defined with Class(CComX), Clsid(CLSID_ComX), Resid(IDR_COMX).
It implements Intid(IA).

class ATL_NO_VTABLE CComX
: public CComObjectRootEx<ccomsinglethreadmodel>,
, public CComCoClass<comx, clsid_comx="">
, public IDispatchImpl
{
CComX();
~CComX();

BEGIN_COM_MAP(CComX)
COM_INTERFACE_ENTRY(IA)
COM_INTERFACE_ENTRY2(IDispatch, IA)
END_COM_MAP()
DECLARE_REGISTRY_RESOURCEID(IDR_COMX)
...
}

OBJECT_ENTRY_AUTO(CLSID_ComX, CComX)


Next, I need to create second coclass implementing the same interface IA but having different Class(CComY), Clsid(CLSID_ComY), and Resid(IDR_COMY).

So, I simply copied the above coclass and replaced 'X' with 'Y'.

class ATL_NO_VTABLE CComY
: public CComObjectRootEx<ccomsinglethreadmodel>,
, public CComCoClass<ccomy, clsid_comy="">
, public IDispatchImpl<ia, &iid_ia,="" &libid_comtlib,="" *wmajor="*/" 1,="" *wminor="*/" 0="">
{
CComY();
~CComY();

BEGIN_COM_MAP(CComY)
COM_INTERFACE_ENTRY(IA)
COM_INTERFACE_ENTRY2(IDispatch, IA)
END_COM_MAP()
DECLARE_REGISTRY_RESOURCEID(IDR_COMY)
...
}

OBJECT_ENTRY_AUTO(CLSID_ComY, CComY)


And I successfully CoCreateInstance'd these two coclasses:

HRESULT hr = S_OK;
ULONG rc = 0;

IA *pXA = NULL;
hr = CoCreateInstance(CLSID_ComX, NULL, CLSCTX_ALL, IID_IA, (void **)&pXA);
rc = pXA->Release();

IA *pYA = NULL;
hr = CoCreateInstance(CLSID_ComY, NULL, CLSCTX_ALL, IID_IA, (void **)&pYA);
rc = pYA->Release();

So far so good!


The problem is that I need to create many coclasses now and in the future.
I don't want to copy/paste for all of them because it is quite hard to maintain the source code for all the copy/paste'd coclasses. It is quite error-prone.
So, I definitely would like to create a class template.

Below, I created a class template and it compiled ok.

template
class ATL_NO_VTABLE CComT
: public CComObjectRootEx,
, public CComCoClass, &CLSID_T>
, public IDispatchImpl
{
CComT()
{
}
~CComT()
{
}

BEGIN_COM_MAP(CComT)
COM_INTERFACE_ENTRY(IA)
COM_INTERFACE_ENTRY2(IDispatch, IA)
END_COM_MAP()
DECLARE_REGISTRY_RESOURCEID(RESID_T)
...
}

//OBJECT_ENTRY_AUTO(CLSID_ComT, CComT)

I hope I am doing right.

Next, I would like to instantiate two template classes to replace the original CComX and CComY classes:

class CComT<clsid_comx, idr_comx="">;
class CComT<clsid_comy, idr_comy="">;


Is this right way to instantiate template coclasses?

And if so, how would I modify the above CoCreateInstance statements?


I have ComT.zip file containing all these classes but don't know how to upload here.
So, if you give me your email, I would send it.

thank you
Questiong++ _fullpath compilation error Pin
PaulS_UK25-Feb-15 3:20
PaulS_UK25-Feb-15 3:20 
SuggestionRe: g++ _fullpath compilation error Pin
Richard MacCutchan25-Feb-15 4:24
mveRichard MacCutchan25-Feb-15 4:24 
AnswerRe: g++ _fullpath compilation error Pin
Jochen Arndt25-Feb-15 4:45
professionalJochen Arndt25-Feb-15 4:45 
GeneralRe: g++ _fullpath compilation error Pin
PaulS_UK25-Feb-15 4:54
PaulS_UK25-Feb-15 4:54 
GeneralRe: g++ _fullpath compilation error Pin
Jochen Arndt25-Feb-15 5:01
professionalJochen Arndt25-Feb-15 5:01 
GeneralRe: g++ _fullpath compilation error Pin
PaulS_UK25-Feb-15 5:04
PaulS_UK25-Feb-15 5:04 
QuestionHow to get User Login and logout time in C++ / MFC .? Pin
mbatra3124-Feb-15 23:05
mbatra3124-Feb-15 23:05 
AnswerRe: How to get User Login and logout time in C++ / MFC .? Pin
Jochen Arndt24-Feb-15 23:43
professionalJochen Arndt24-Feb-15 23:43 
QuestionRe: How to get User Login and logout time in C++ / MFC .? Pin
David Crow25-Feb-15 5:49
David Crow25-Feb-15 5:49 
AnswerRe: How to get User Login and logout time in C++ / MFC .? Pin
mbatra3125-Feb-15 19:21
mbatra3125-Feb-15 19:21 
GeneralRe: How to get User Login and logout time in C++ / MFC .? Pin
Frankie-C25-Feb-15 21:32
Frankie-C25-Feb-15 21:32 
GeneralRe: How to get User Login and logout time in C++ / MFC .? Pin
David Crow26-Feb-15 2:22
David Crow26-Feb-15 2:22 
QuestionDynamic Menu Creation Pin
Thakur JAI SINGH24-Feb-15 20:57
Thakur JAI SINGH24-Feb-15 20:57 
AnswerRe: Dynamic Menu Creation Pin
_Flaviu24-Feb-15 21:29
_Flaviu24-Feb-15 21:29 
GeneralRe: Dynamic Menu Creation Pin
Thakur JAI SINGH24-Feb-15 22:22
Thakur JAI SINGH24-Feb-15 22:22 
GeneralRe: Dynamic Menu Creation Pin
_Flaviu25-Feb-15 0:10
_Flaviu25-Feb-15 0:10 
GeneralRe: Dynamic Menu Creation Pin
Thakur JAI SINGH25-Feb-15 0:30
Thakur JAI SINGH25-Feb-15 0:30 

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.