Click here to Skip to main content
15,903,033 members
Home / Discussions / COM
   

COM

 
GeneralRe: Problems passing a DISPPARAMS structure to IDispatch::Invoke Pin
Vi223-Dec-03 23:36
Vi223-Dec-03 23:36 
GeneralRe: Problems passing a DISPPARAMS structure to IDispatch::Invoke Pin
Dark Magus25-Dec-03 11:34
Dark Magus25-Dec-03 11:34 
GeneralRe: Problems passing a DISPPARAMS structure to IDispatch::Invoke Pin
Vi225-Dec-03 19:21
Vi225-Dec-03 19:21 
GeneralRe: Problems passing a DISPPARAMS structure to IDispatch::Invoke Pin
Dark Magus26-Dec-03 10:03
Dark Magus26-Dec-03 10:03 
Generalabout LocalServer COM Register Pin
yingkou22-Dec-03 15:05
yingkou22-Dec-03 15:05 
GeneralRe: about LocalServer COM Register Pin
User 78226222-Dec-03 23:16
professionalUser 78226222-Dec-03 23:16 
GeneralRe: about LocalServer COM Register Pin
Vi223-Dec-03 23:29
Vi223-Dec-03 23:29 
GeneralCOM Apartments and Marshalling Pin
Jörgen Sigvardsson22-Dec-03 14:03
Jörgen Sigvardsson22-Dec-03 14:03 
Would this be safe? (the following code is implemented in a DLL, used by a single EXE D'Oh! | :doh: and a bunch of COM DLLs)
CComAutoCriticalSection cs;
DWORD                   dwOwnerThreadId;
ISomeInterface*         pObject = 0;
IStream*                pObjMarshalled = 0;
 
HRESULT RegisterGlobalObject(ISomeInterface* pObj)
{
    if(!cs.Lock()) 
        return E_FAIL;
     
    if(pObject != 0) {
        cs.Unlock();
        return E_UNEXPECTED;
    }
 
    HRESULT hr = CoMarshalInterThreadInterfaceInStream(
        __uuidof(ISomeInterface),
        pObj,
        &pObjMarshalled
    );
 
    if(FAILED(hr)) {
        cs.Unlock();
        return hr;
    }
 
    pObject = pObj;
    dwOwnerThreadId = GetCurrentThreadId();
    cs.Unlock();
 
    return S_OK;
}
  
HRESULT GetGlobalObject(ISomeInterface** ppObj)
{
    if(!ppObj)
        return E_POINTER;

    if(!pObject)
        return E_FAIL;
    
    if(!cs.Lock())
        return E_FAIL;
    
    if(GetCurrentThreadId() == dwOwnerThreadId) {
        *ppObj = pObject;
        (*ppObject)->AddRef();
        cs.Unlock();
        return S_OK;
    }
 
    *ppObj = 0;
 
    LARGE_INTEGER seek;
    seek.QuadPart = 0; 
    HRESULT hr = pObjMarshalled->Seek(seek, STREAM_SEEK_SET, NULL);
    if(FAILED(hr) {
        cs.Unlock();
        return hr;
    }
 
    hr = CoUnmarshalInterface(
        pObjMarshalled, 
        __uuidof(ISomeInterface), 
       (void**)ppObj
    );
 
    cs.Unlock();
    return hr;
}


I'm marshalling the interface pointer upon registration using the inter thread marshalling function, because I know that this function will not be called from any other process (it can't be). I also assume that CoUnmarshalInterface() will work for interfaces marshalled with CoMarshalInterThreadInterfaceInStream().

I have yet to try this out (it's way past bedtime Roll eyes | :rolleyes: ). But if you read this and spot any inherent danger with this code, please let me know. Smile | :)

--
Sancte Míchael Archángele, defénde nos in proélio contra nequítiam et
insídias diáboli esto præsídium. Imperet illi Deus, súpplices deprecámur:
tuque, princeps milítiæ cæléstis, Sátanam aliósque spíritus malígnos, qui
ad perditiónem animárum pervagántur in mundo, divína virtúte,
In inférnum detrude. Amen.

GeneralNo, that sucked Pin
Jörgen Sigvardsson23-Dec-03 7:07
Jörgen Sigvardsson23-Dec-03 7:07 
GeneralRe: No, that sucked Pin
geo_m30-Dec-03 0:32
geo_m30-Dec-03 0:32 
GeneralAll COM that expose a specific interface Pin
IreneVassileva22-Dec-03 0:00
IreneVassileva22-Dec-03 0:00 
GeneralRe: All COM that expose a specific interface Pin
Abhishek Srivastava22-Dec-03 1:01
Abhishek Srivastava22-Dec-03 1:01 
GeneralYahoo messenger login interface. Urgent Pin
SiddharthAtw21-Dec-03 18:35
SiddharthAtw21-Dec-03 18:35 
QuestionHow to access COM objects during runtime? Pin
dapipi21-Dec-03 17:13
dapipi21-Dec-03 17:13 
AnswerRe: How to access COM objects during runtime? Pin
Anonymous21-Dec-03 18:47
Anonymous21-Dec-03 18:47 
AnswerRe: How to access COM objects during runtime? Pin
Anonymous21-Dec-03 18:52
Anonymous21-Dec-03 18:52 
AnswerRe: How to access COM objects during runtime? Pin
Abhishek Srivastava21-Dec-03 19:07
Abhishek Srivastava21-Dec-03 19:07 
GeneralRe: How to access COM objects during runtime? Pin
dapipi22-Dec-03 19:30
dapipi22-Dec-03 19:30 
GeneralLookgin for good COM+ book suggestions Pin
Flack21-Dec-03 14:16
Flack21-Dec-03 14:16 
GeneralIRunnableTask and IExtractImage Pin
ohadp18-Dec-03 1:45
ohadp18-Dec-03 1:45 
GeneralHelp me for COM+ design with C#.NET Pin
Simi Agarwal17-Dec-03 21:37
Simi Agarwal17-Dec-03 21:37 
QuestionHow to capture mouse event in MS word? Pin
aw1ay17-Dec-03 15:55
aw1ay17-Dec-03 15:55 
GeneralMS Active Accessibility problem Pin
visharma17-Dec-03 10:52
visharma17-Dec-03 10:52 
GeneralCreating WorksheetFunctions for Excel Office XP Pin
ThOmAs2217-Dec-03 8:23
ThOmAs2217-Dec-03 8:23 
GeneralAccess IDispatch from C Pin
Spiros17-Dec-03 2:45
Spiros17-Dec-03 2:45 

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.