Hi,
I'm dealing with some automation for my code, and there is some syntax that is there that confuses me
I have code like this:
BEGIN_DISPATCH_MAP(MyDocument, CCmdTarget)
//{{AFX_DISPATCH_MAP(MyDocument)
DISP_FUNCTION(MyDocument, "SetVisible", SetVisible, VT_EMPTY, VTS_BOOL)
//}}AFX_DISPATCH_MAP
DISP_FUNCTION(MyDocument, "SetInvisible", SetInvisible, VT_EMPTY, VTS_BOOL)
END_DISPATCH_MAP()
The part i dont understand is why the AFX_DISPATH_MAP line is commented out And why all code between the AFX_DISPATH_MAP lines is a different colour (grayed out in VS2003). This functions must still work as they do in fact work, but what would the differrence be between the SetVisible and SetInvisible method calls. This style of commenting out the AFX_DISPATH_MAP lines is present in sample code at MSDN, but i cannot find an explanation for it In the example above, what in fact is the difference between the two differing lines referring to dispatch functions How do they behave differently, if at all, etc
Many thanks
Will

Question Regarding Automation
uasking
BEGIN_DISPATCH_MAP(MyDoc,COleServerDoc)
DISP_FUNCTION_ID(MyDoc, "GetScript", dispidGetScript, GetScript, VT_BSTR, VTS_NONE)
DISP_FUNCTION_ID(MyDoc, "SetPenColor", dispidSetPenColor, SetPenColor, VT_I4, VTS_I4)
DISP_FUNCTION(MyDoc, "GetBoxColor", GetBoxColor, VT_I4, VTS_NONE) END_DISPATCH_MAP
that third line that refers to "GetBoxColor" is the one i am trying to add. It produces the following erros upon compiling
error C2146: syntax error: missing ';' before identifier 'TS_I4'
error C2146: syntax error: missing '}' before identifier 'TS_I4'
error C2146: syntax error: missing '}' before identifier 'TS_I4'
fatal error C1075: end of file found before the left brace '{' at 'myFileDoc.cpp(304)' was matched
line 304 refers to the line containing the DISP_FUNCTION_ID call to SetPenColor and is the line given for the other 3 problems as well.
I dont even have a clue here, any ideas
Will
German_Steffen
If a function is called Save, there must be only 1 implementation there is NO overloading. This has nothing to do with C++ it is a OLE automation problem!
overseb
Will
Sing Hee
BEGIN_DISPATCH_MAP(STUFF, COleServer)
/*the change here is that the internal function used for saving is called save1*/
DISP_FUNCTION_ID(STUFF,"Save",dispidSave,Save1,VT_l4,VTS_NONE)
/*the internal function called here is just called save, which gets around the over-riding from the internal functions point of view, but the name still supplied in " " is the same*/
DISP_FUNCTION(STUFF,"Save",Save,VT_BOOL,VTS_BSTR)
END_DISPATCH_MAP
Would this work, sorry i know this one is a pain in the ***.
Will
Toranoshi22
1. About the dispatch ID
The macros DISP_FUNCTION/DISP_PARAMETER determines the Dispatch ID by position, so there is an internal counter. So rearranging the dispatch map usually causes a lot of clients to fail, if the just use the dispatch ID!
Read:
http://msdn.microsoft.com/library/default.asp url=/library/en-us/vclib/html/_mfcnotes_tn039.asp
DISP_FUNCTION_ID defines the specific dispatch ID.
2. COM/OLE does not support overloading.
A name and its parameters must be fixed. But! You can make all parameters VARIANT fields and support scode DISP_E_PARAMNOTFOUND! In the idl the parameters can be defined as optional.
HTH
irarabesc
obviously the methods are different, but in the fundamental behavior is there any difference Also if this was just necessary for VC6, can i get rid of the commented lines in VS2003.
KLCurry
Ok, i see, so just so i understand this properly, this would work (although i cant see any point of it, just so i understand)
BEGIN_DISPATCH_MAP(STUFF, COleServer)
DISP_FUNCTION_ID(STUFF,"Save1",dispidSave,Save,VT_l4,VTS_NONE)
DISP_FUNCTION(STUFF,"Save",Save,VT_BOOL,VTS_BSTR)
END_DISPATCH_MAP
Different type of overloading, would it work
Thanks
Will
Marek Istvanek
No these lines are interpreted in the same way. You can remove the comments in VS.NET 200x!
Sampy
klingmeister
thats great, one more question though, concerning overriding. I havent even checked if u can do this in c++ incidently (java guy originally).
Could i do this:
BEGIN_DISPATCH_MAP(STUFF,COleServerDoc)
/*this line should work*/
DISP_FUNCTION(STUFF,"Save",Save,VT_BOOL,VTS_BSTR)
/*will this work , in the sense that is is still a save message being called */
DISP_FUNCTION_ID(STUFF,"Save",dispidSave,Save,VT_l4,VTS_NONE)
/*will this realise that there are two different methods for save, each with different parameters, and call the correct one */
DISP_FUNCTION(STUFF,"Save",Save,VT_l4,VTS_NONE
END_DISPATCH_MAP()
Thanks
Will
ming_68
So in the old VC6 those parts should not be edited manually.
The new syntax parser still shows this colouring.
Daapower
sorry for wasting your time
will
zoe305
jafar
Will