473,396 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

COM Interop problem...

Hi,

Introduction:
*********************
I am writing a mixed mode application I have a COM module and a .NET module
that communicate with each other.
The COM exposes a custom sink interface, the .NET module implement the Sink
interface ( IUnknown based ) and the COM call the methods of this interface
asynchronously.

The problem:
*********************
When calling the sink methods on the .NET module from the context of a
managed thread ( the main app thread ) created by the .NET framework
everything works fine BUT when calling the sink methods ( implemented by the
managed module ) from an unmanaged thread that was created by the COM module
I get E_NOINTERFACE.

Note that The managed sink implementation is associated with the COM module
through an Advice( ISink sink, ref uint uiContext ) method.

What may cause this problem? I called CoInitializeEx on all of the new
unmanaged threads…

Following is a code snap of the two modules:

Unmanaged COM:
################################################
interface IMediaEvents
{
virtual HRESULT OnState(eState state, VARIANT &var) = 0;
};

Protected:
HRESULT Fire_OnState(IN eState state, IN VARIANT &var)
{
HRESULT hrRet = S_OK;
SinkVector_t::iterator itr = m_vecSink.begin();
while(itr != m_vecSink.end())
{
//////////////////////////////
// Returns E_NOINTERFACE!!!
if(FAILED((*itr)->OnState(state, var)))
hrRet = S_FALSE;
//////////////////////////////
itr++;
}
return hrRet;
}

Public:
STDMETHOD(Advise)(IMediaEvents* pSink,
ULONG* pulCookie)
{
…
while(itr != m_vecSink.end())
{
if(pSink == (*itr).p)
return HRESULT_FROM_WIN32(ERROR_ALREADY_CONNECTED);
itr++;
}
m_vecSink.push_back(spSink);
*pulCookie = (ULONG)spSink.p;
return S_OK;
}

STDMETHOD(Unadvise)(/*[in]*/ ULONG ulCookie)
{
…
}

Managed Sink
##############################
public class Form1 : System.Windows.Forms.Form
, StreamingServerLib.IMediaEvents
{
…
…
…
private void btnRecord_Click(object sender, System.EventArgs e)
{
if(null != m_RecordSession)
{
m_RecChan.Unadvise(m_uiRecCookie);
m_MediaBuffer.CloseSession(m_RecordSession);
m_RecordSession = null;
}
m_RecChan = null;
m_RecChan = m_MediaBuffer.CreateChan(txtOutputPath.Text, -1);
///////////////////////////////////////////////
// Connects with the COM object
m_uiRecCookie = m_RecChan.Advise(this);
…
m_RecordSession.Start(txtSourcePath.Text);
}

/////////////////////////////////////////////////////////////////
// Called by the COM only when executed from a managed thread
// when invoked by an unmanaged thread E_NOINTERFACE is returned
// to the unmanaged caller
public void OnState(StreamingServerLib.eState state,
object varParam)
{
…
}
…
…
};

--
Nadav
http://www.sophin.com
Nov 17 '05 #1
1 2268
I am not sure, but it appears to me that you are trying to handle events
from a COM dll in a .Net exe??? If this is so, you do not need to implement
the sink interface on your receiving object as you do in COM. You can use
the += operator to add an event handler just as you would in managed code.
Interop does all the intermediate work for you.
"Nadav" <Na***@discussions.microsoft.com> wrote in message
news:CD**********************************@microsof t.com...
Hi,

Introduction:
*********************
I am writing a mixed mode application I have a COM module and a .NET
module
that communicate with each other.
The COM exposes a custom sink interface, the .NET module implement the
Sink
interface ( IUnknown based ) and the COM call the methods of this
interface
asynchronously.

The problem:
*********************
When calling the sink methods on the .NET module from the context of a
managed thread ( the main app thread ) created by the .NET framework
everything works fine BUT when calling the sink methods ( implemented by
the
managed module ) from an unmanaged thread that was created by the COM
module
I get E_NOINTERFACE.

Note that The managed sink implementation is associated with the COM
module
through an Advice( ISink sink, ref uint uiContext ) method.

What may cause this problem? I called CoInitializeEx on all of the new
unmanaged threads.

Following is a code snap of the two modules:

Unmanaged COM:
################################################
interface IMediaEvents
{
virtual HRESULT OnState(eState state, VARIANT &var) = 0;
};

Protected:
HRESULT Fire_OnState(IN eState state, IN VARIANT &var)
{
HRESULT hrRet = S_OK;
SinkVector_t::iterator itr = m_vecSink.begin();
while(itr != m_vecSink.end())
{
//////////////////////////////
// Returns E_NOINTERFACE!!!
if(FAILED((*itr)->OnState(state, var)))
hrRet = S_FALSE;
//////////////////////////////
itr++;
}
return hrRet;
}

Public:
STDMETHOD(Advise)(IMediaEvents* pSink,
ULONG* pulCookie)
{
.
while(itr != m_vecSink.end())
{
if(pSink == (*itr).p)
return HRESULT_FROM_WIN32(ERROR_ALREADY_CONNECTED);
itr++;
}
m_vecSink.push_back(spSink);
*pulCookie = (ULONG)spSink.p;
return S_OK;
}

STDMETHOD(Unadvise)(/*[in]*/ ULONG ulCookie)
{
.
}

Managed Sink
##############################
public class Form1 : System.Windows.Forms.Form
, StreamingServerLib.IMediaEvents
{
.
.
.
private void btnRecord_Click(object sender, System.EventArgs e)
{
if(null != m_RecordSession)
{
m_RecChan.Unadvise(m_uiRecCookie);
m_MediaBuffer.CloseSession(m_RecordSession);
m_RecordSession = null;
}
m_RecChan = null;
m_RecChan = m_MediaBuffer.CreateChan(txtOutputPath.Text, -1);
///////////////////////////////////////////////
// Connects with the COM object
m_uiRecCookie = m_RecChan.Advise(this);
.
m_RecordSession.Start(txtSourcePath.Text);
}

/////////////////////////////////////////////////////////////////
// Called by the COM only when executed from a managed thread
// when invoked by an unmanaged thread E_NOINTERFACE is returned
// to the unmanaged caller
public void OnState(StreamingServerLib.eState state,
object varParam)
{
.
}
.
.
};

--
Nadav
http://www.sophin.com

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Nadav | last post by:
Hi, Introduction *************** I have a system build of a collection of 'Native COM objects' and '.NET COM interop' objects, all of the COM objects are managed through a 'Native COM' layer,...
20
by: Razzie | last post by:
Hey all, I'm really going through a small hell right now - I've completely lost it :) I made a project, using two interop libraries from exchange (created them as in this msdn article:...
1
by: Shiro | last post by:
Hi I have read the various postings relating to Interop strong name signing and cannot find an example similar to mine. I have stringly named my AxInterops/Interops and they all work just...
8
by: Rob Edwards | last post by:
When trying to add the Microsoft CDO for Exchange Management Library (aka CDOEXM.dll) I receive the following message: "A reference to 'Microsoft CDO for Exchange Management Library' could not be...
7
by: R Reyes | last post by:
Can someone please explain to me why I can't get the MS Word Interop assembly to work in my VS2005 project? I'm trying to manipulate MS Word from my Web Form application and I can't get passed...
3
by: Hospital S.Sebastiao | last post by:
Hi, i'm in desperate need of help to fix a problem that i have, the problem is the following: I have an ASP.NET aplication that to open an word template document, this aplication is in C#(using...
2
by: JC | last post by:
Anybody knows what problem has this code? I think, in the Garbage Collector? You know the Solution? The program in the test's case, whit 350 contacts, run OK before number 86. The error is a...
1
by: Don.Leri | last post by:
Hi, I have a logger.dll (unmanaged c++ dll compiled in vs2005). I have a C# interop to use that dll in managed code implemented in Interfaces.dll (used by other C# dlls). I also have a...
1
by: allbelonging | last post by:
C#.Net Outlook 2003 automation (programmatically) with Office.Interop.Outlook Problem: I have my outlook 2003 configured with multiple mailbox on my local machine. I want to specify the mailbox...
0
by: Tina | last post by:
I've gotten this before where it says there is a problem with Interop.MSDASC but I can't remember what causes this. This is a 1.1 app I'm trying to debug in vs2005. It was running yesterday just...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.