Click here to Skip to main content
15,890,741 members
Home / Discussions / COM
   

COM

 
GeneralRe: VBScript and COM Pin
Vivek Rajan21-May-02 9:16
Vivek Rajan21-May-02 9:16 
GeneralRe: VBScript and COM Pin
Jim Crafton23-May-02 16:57
Jim Crafton23-May-02 16:57 
GeneralRe: VBScript and COM Pin
Vivek Rajan23-May-02 18:16
Vivek Rajan23-May-02 18:16 
GeneralRe: VBScript and COM Pin
Jim Crafton24-May-02 3:08
Jim Crafton24-May-02 3:08 
GeneralRe: VBScript and COM Pin
Vi224-May-02 3:35
Vi224-May-02 3:35 
GeneralRe: VBScript and COM Pin
soptest24-May-02 7:16
soptest24-May-02 7:16 
QuestionCringeworthy Cast in ATL?? Pin
20-May-02 23:23
suss20-May-02 23:23 
AnswerRe: Cringeworthy Cast in ATL?? Pin
Vivek Rajan21-May-02 6:50
Vivek Rajan21-May-02 6:50 
Anonymous wrote:
//////////this is the 'nasty' part it does work but I dont like it!!
//////////is there a more elegant way to achieve this or is what I am doing OK?
CMyComObject* pMyBodgeCast = dynamic_cast(pMyComObject);
pMyBodgeCast->m_pConnectedTo = this;
//////////////////////////////////////////////////////////////////////////


Hi -

What you are doing is clearly bad !! I think casting an interface to an implementation goes against the very princple of COM (separation of impl and interface).
It works for you because
(a) you have an INPROC DLL, so there is no marshalling
(b) you guarantee that the only implementaton of IMYComObject is CMyCOMObject.

I had a similar problem when I wanted prvate interfaces. I think this is a major limitation of COM interfaces. You can use the [hidden] or [restricted] keywords in IDL. But that wouldnt prevent C++ users from using it. If you dont include it in the typelib,or register it, then it wont be marshalled across apartments. The solution I used is kludgy, have a private token or key as a parameter for each of the interface methods. So, the private interface would be visible, but not usable by others because they dont know the secret key.


Here is how you might do this.
1) Specify the [hidden] or [restricted] keyword in the IDL for the IMyComObjectPrivateUse, so VB cant use it.
2) Create a private interface IMyComObjectPrivateUse, add the method SetConnectedObject(DWORD token,IMyComObject *)
3) Implement IMyComObjectPrivateUse in CMyComObject, the method looks like
// IMyComObjectPrivateUse (For Private Use Only)
// Depending on your need for security you can have a 
// fancy authentication scheme if you wish
STDMETHODIMP CMyComObject::SetConnectedObject(DWORD token,IMyComObject *pObj)
{
   if(token!=0xfeedf00d) {  // 0xfeedf00d is your secret key
     return E_NOTIMPL;
   }
   pObj->AddRef();
   m_pConnectedTo=pObj;
   return S_OK;
}

4) In your ConnectTo implementation, just QI for IMyComObjectPrivateUse and call the set method with the correct key
IMyComObjectPrivateUse * pPriv;
pMyComObject->QI(IID_IMYComObjcetPrivateUse,(LPVOID*)&pPriv)
pPriv->SetConnected(0xfeedf00d,pMyComObject);



I would love to hear anyone who has other ideas. I am currently using the above mechanism.

Hope that helps -
Vivek
GeneralRe: Cringeworthy Cast in ATL?? Pin
soptest21-May-02 7:41
soptest21-May-02 7:41 
GeneralRe: Cringeworthy Cast in ATL?? Pin
Vivek Rajan21-May-02 9:08
Vivek Rajan21-May-02 9:08 
GeneralRe: Cringeworthy Cast in ATL?? Pin
soptest21-May-02 10:32
soptest21-May-02 10:32 
GeneralRe: Cringeworthy Cast in ATL?? Pin
Vivek Rajan21-May-02 10:53
Vivek Rajan21-May-02 10:53 
GeneralRe: Cringeworthy Cast in ATL?? Pin
soptest21-May-02 12:10
soptest21-May-02 12:10 
GeneralRe: Cringeworthy Cast in ATL?? Pin
NotYourAverageGuy6-Jun-02 9:13
NotYourAverageGuy6-Jun-02 9:13 
GeneralRe: Cringeworthy Cast in ATL?? Pin
21-May-02 22:15
suss21-May-02 22:15 
GeneralRe: Cringeworthy Cast in ATL?? Pin
Vivek Rajan23-May-02 16:33
Vivek Rajan23-May-02 16:33 
GeneralCOM+ deployment help Pin
Annesa20-May-02 2:25
Annesa20-May-02 2:25 
GeneralRe: COM+ deployment help Pin
soptest20-May-02 9:40
soptest20-May-02 9:40 
Generaldrag and drop destination Pin
20-May-02 0:39
suss20-May-02 0:39 
GeneralRe: drag and drop destination Pin
soptest20-May-02 9:31
soptest20-May-02 9:31 
GeneralCannot expose interface Pin
Hans Ruck19-May-02 21:51
Hans Ruck19-May-02 21:51 
GeneralRe: Cannot expose interface Pin
soptest20-May-02 9:36
soptest20-May-02 9:36 
GeneralRe: Cannot expose interface Pin
Hans Ruck20-May-02 22:44
Hans Ruck20-May-02 22:44 
GeneralRe: Cannot expose interface Pin
Vi221-May-02 1:06
Vi221-May-02 1:06 
GeneralRe: Cannot expose interface Pin
Vi226-May-02 20:56
Vi226-May-02 20:56 

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.