Click here to Skip to main content
16,008,490 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: quick question about message reflection Pin
Tomasz Sowinski26-Jul-02 1:06
Tomasz Sowinski26-Jul-02 1:06 
GeneralRe: quick question about message reflection Pin
ns26-Jul-02 1:29
ns26-Jul-02 1:29 
Generalcomctl32 crashes Pin
alaulu26-Jul-02 0:43
alaulu26-Jul-02 0:43 
GeneralPlugin Extensions Pin
laphijia26-Jul-02 0:35
laphijia26-Jul-02 0:35 
GeneralRe: Plugin Extensions Pin
Tomasz Sowinski26-Jul-02 1:00
Tomasz Sowinski26-Jul-02 1:00 
GeneralRe: Plugin Extensions Pin
Chris Losinger26-Jul-02 4:25
professionalChris Losinger26-Jul-02 4:25 
GeneralRe: Plugin Extensions Pin
laphijia26-Jul-02 7:30
laphijia26-Jul-02 7:30 
GeneralRe: Plugin Extensions Pin
Chris Losinger26-Jul-02 8:03
professionalChris Losinger26-Jul-02 8:03 
COM is a huge subject. but, here is a link to a tutorial i wrote on how to create plugins for my apps. you can use VC's ATL wizard to do most of the work.

to use these plugins, you need to create a COleDispatchDriver object and use it to create an instance of the plugin:

// i chose to name my plugin interface "TNImgAutomation"
cosnt char * pInterfaceName = "TNImgAutomation";

// one of the plugin rules is that the plugin object's name must be the same as the DLLs name
CString csPluginObjectName = csDLLName + pInterfaceName;

COleDispatchDriver disp;
BOOL ok = disp.CreateDispatch(csPluginObjectName);


now we have a plugin object. the next part is to call methods of the plugin. this is where it gets tricky, in my system. because i create COleDispatchDriver objects directly, I am responsible for finding the methods and handling all of the method parameters myself.

Here's how you get the DISPID of a method in an ActiveX object (DISPID is basically the enumerated ID of the method. each method will have a unique ID).

HRESULT GetDispID(COleDispatchDriver &disp, const char *pName, DISPID &dispid)
{
	USES_CONVERSION;
	LPOLESTR lpOleStr = T2OLE(pName);

	if (disp.m_lpDispatch==NULL)
	{
		ASSERT(0);
		return E_INVALIDARG;
	}

	return disp.m_lpDispatch->GetIDsOfNames(IID_NULL, &lpOleStr, 1, LOCALE_SYSTEM_DEFAULT, &dispid);
}


so you can do this:

DISPID dispid;
GetDispID(disp, "GetPluginName", dispid);


now you know the ID of that method. now you can call it.

here's how I call "GetPluginName" on a plugin:

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

CString CTNPlugInBase::GetPluginName()
{
	CString csOut;
	BSTR bsTemp;

	long result;
	static BYTE parms[] =
		VTS_PBSTR;
	disp.InvokeHelper(m_GetPluginNamesDispID, DISPATCH_METHOD, VT_I4, (void*)&result, parms, &bsTemp);

	csOut = bsTemp;
	SysFreeString(bsTemp);

	return csOut;
}


the tricky part here is that "parms" variable. that's where you list the parameters for the method. with one parameter (in this case a pointer to a BSTR: &bsTemp), it's pretty easy. but when you get more parameters, it looks like this:

long result;
static BYTE parms[] =
	VTS_PI4 VTS_PI4 VTS_PI4 VTS_I4 ;

disp.InvokeHelper(dispId, DISPATCH_METHOD, VT_I4, (void*)&result, parms, MemoryHandle, Width, Height, Context);


notice that there are no commas between those VTS_ things.

this might seem really horribly complicated if you've never used COM/ATL before. but it's really not too bad, once you get into it.

-c


To explain Donald Knuth's relevance to computing is like explaining Paul's relevance to the Catholic Church. He isn't God, he isn't the Son of God, but he was sent by God to explain God to the masses.
   /. #3848917

GeneralModify windows style Pin
Antony B.26-Jul-02 0:05
sussAntony B.26-Jul-02 0:05 
GeneralRe: Modify windows style Pin
includeh1026-Jul-02 1:29
includeh1026-Jul-02 1:29 
GeneralAsk about FillRect() Pin
25-Jul-02 22:57
suss25-Jul-02 22:57 
GeneralRe: Ask about FillRect() Pin
pépé26-Jul-02 2:41
pépé26-Jul-02 2:41 
GeneralConvert From Wave to MP3 - format C++ Pin
haronis25-Jul-02 22:15
haronis25-Jul-02 22:15 
GeneralRe: Convert From Wave to MP3 - format C++ Pin
benjymous26-Jul-02 0:01
benjymous26-Jul-02 0:01 
GeneralRe: Convert From Wave to MP3 - format C++ Pin
haronis26-Jul-02 0:05
haronis26-Jul-02 0:05 
GeneralRe: Convert From Wave to MP3 - format C++ Pin
benjymous26-Jul-02 0:12
benjymous26-Jul-02 0:12 
GeneralRe: Convert From Wave to MP3 - format C++ Pin
laphijia26-Jul-02 0:43
laphijia26-Jul-02 0:43 
GeneralRe: Convert From Wave to MP3 - format C++ Pin
pépé26-Jul-02 2:44
pépé26-Jul-02 2:44 
GeneralService startup problems Pin
s_k25-Jul-02 22:14
s_k25-Jul-02 22:14 
GeneralRe: Service startup problems Pin
Daniel Lohmann25-Jul-02 22:35
Daniel Lohmann25-Jul-02 22:35 
QuestionTroubled!! - List of existing Menu shortcuts?? Pin
Dave Matrix25-Jul-02 22:10
Dave Matrix25-Jul-02 22:10 
AnswerRe: Troubled!! - List of existing Menu shortcuts?? Pin
Tomasz Sowinski25-Jul-02 23:49
Tomasz Sowinski25-Jul-02 23:49 
GeneralCListCtrl - LVN_ITEMCHANGED Pin
Niko Tanghe25-Jul-02 21:52
Niko Tanghe25-Jul-02 21:52 
GeneralRe: CListCtrl - LVN_ITEMCHANGED Pin
Tomasz Sowinski25-Jul-02 23:43
Tomasz Sowinski25-Jul-02 23:43 
GeneralRe: CListCtrl - LVN_ITEMCHANGED Pin
Niko Tanghe26-Jul-02 0:03
Niko Tanghe26-Jul-02 0:03 

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.