OLE and Worker Threads.
FIGNET05.DARRINS@eds.com
Wednesday, February 19, 1997
Environment: VC++ 4.2b NT 4.0 with all patches
I have a multi-threaded application that needs to communicate with
another MFC based application through OLE. When I try to do a
VERIFY(m_Data.CreateDispatch("OleServer.Data")==TRUE); inside the worker
thread I get an assertion failure and the following warning:
CreateDispatch returning scode = CO_E_NOTINITIALIZED ($800401F0).
If I place this code in a non-threaded app or move it outside of the
thread (to my view class for example) everything works fine.
Is there something special that I need to do with CreateDispatch inside a
thread?
Here is a code snippet of what I am currently doing:
UINT ProcessThisConnection(LPVOID pVoidReceiveSocketInfo)
{
CSocketInfo* pReceiveSocketInfo =
(CSocketInfo*)pVoidReceiveSocketInfo;
IData m_Data;
[more code snipped]
VERIFY(m_Data.CreateDispatch("OleServer.Data")==TRUE);
sOutBoundTCP=m_Data.ProcessData("TESTING");
m_Data.ReleaseDispatch();
[more code snipped]
}
Stefan Thiel
Thursday, February 20, 1997
I had the same. I initialize OLE now in each thread
that uses OLE (something like AfxOleInit(), see the
InitInstance of your ...App class when created with
appwizard giving OLE support. There is this OLE init
function called for the main thread). Up to now this
worked fine for me.
Hope this helps.
Bing Hou -- hou@tfn.com
Thursday, February 20, 1997
[Mini-digest: 3 responses]
This has to do with the 'OLE threading model'(search for this in MSDN).
When you call CoInitilize(or AfxOleInit calls it for you), you are using
the apartment threading model, therefore, you have to call CoInitilize in
your worker thread in order to use OLE functions such as CreateDispatch.
Remember to uninitilize OLE after your thread terminates.
Bing Hou
hou@tfn.com
------------------------------------------------------------------------
"The saints are the sinners who keep on trying."
______________________________ Reply Separator _________________________________
Subject: OLE and Worker Threads.
Author: FIGNET05.DARRINS@eds.com at Internet
Date: 2/19/97 2:17 PM
Environment: VC++ 4.2b NT 4.0 with all patches
I have a multi-threaded application that needs to communicate with
another MFC based application through OLE. When I try to do a
VERIFY(m_Data.CreateDispatch("OleServer.Data")==TRUE); inside the worker
thread I get an assertion failure and the following warning:
CreateDispatch returning scode = CO_E_NOTINITIALIZED ($800401F0).
If I place this code in a non-threaded app or move it outside of the
thread (to my view class for example) everything works fine.
Is there something special that I need to do with CreateDispatch inside a
thread?
Here is a code snippet of what I am currently doing:
UINT ProcessThisConnection(LPVOID pVoidReceiveSocketInfo)
{
CSocketInfo* pReceiveSocketInfo =
(CSocketInfo*)pVoidReceiveSocketInfo;
IData m_Data;
[more code snipped]
VERIFY(m_Data.CreateDispatch("OleServer.Data")==TRUE);
sOutBoundTCP=m_Data.ProcessData("TESTING");
m_Data.ReleaseDispatch();
[more code snipped]
}
-----From: "Sasa.Conic"
You must initialize OLE libraries in each thread that calls OLE
functions.
>----------
>From: FIGNET05.DARRINS@eds.com[SMTP:FIGNET05.DARRINS@eds.com]
>Sent: Wednesday, February 19, 1997 2:17 PM
>To: The recipient's address is unknown.
>Subject: OLE and Worker Threads.
>
>
>
>Environment: VC++ 4.2b NT 4.0 with all patches
>
>I have a multi-threaded application that needs to communicate with
>another MFC based application through OLE. When I try to do a
>VERIFY(m_Data.CreateDispatch("OleServer.Data")==TRUE); inside the worker
>thread I get an assertion failure and the following warning:
>CreateDispatch returning scode = CO_E_NOTINITIALIZED ($800401F0).
>
>If I place this code in a non-threaded app or move it outside of the
>thread (to my view class for example) everything works fine.
>
>Is there something special that I need to do with CreateDispatch inside a
>thread?
>
>Here is a code snippet of what I am currently doing:
>
>UINT ProcessThisConnection(LPVOID pVoidReceiveSocketInfo)
>{
> CSocketInfo* pReceiveSocketInfo =
>(CSocketInfo*)pVoidReceiveSocketInfo;
> IData m_Data;
>
>
> [more code snipped]
>
> VERIFY(m_Data.CreateDispatch("OleServer.Data")==TRUE);
>
> sOutBoundTCP=m_Data.ProcessData("TESTING");
>
> m_Data.ReleaseDispatch();
>
> [more code snipped]
>
>
>}
>
>
-----From: Nathan Cornillon
While I don't know about your specific problem, I've had problems with =
OLE Controls & worker-threads. It seemed a lot of OLE stuff expects =
there to be a message pump going in the thread, also they often expect =
there to be a valid hWnd in the thread. The worker thread I was working =
with had neither (or at least seemed to have neither).
As a quick work around, I had my worker thread send a message to my =
main/UI thread to do whatever action I couldn't get to work from the =
worker. I used SendNotifyMessage. While that's not an answer, I hope =
it helps to spur you on.
Nathan
-----Original Message-----
From: FIGNET05.DARRINS@eds.com [SMTP:FIGNET05.DARRINS@eds.com]
Sent: Wednesday, February 19, 1997 1:17 PM
To: "mfc-l(a)netcom.com":;;;@majordomo.netcom.com@netcom.com;
Subject: OLE and Worker Threads.
Environment: VC++ 4.2b NT 4.0 with all patches
I have a multi-threaded application that needs to communicate with
another MFC based application through OLE. When I try to do a
VERIFY(m_Data.CreateDispatch("OleServer.Data")=3D=3DTRUE); inside the =
worker
thread I get an assertion failure and the following warning:
CreateDispatch returning scode =3D CO_E_NOTINITIALIZED ($800401F0).
If I place this code in a non-threaded app or move it outside of the
thread (to my view class for example) everything works fine.
Is there something special that I need to do with CreateDispatch inside =
a
thread?
Here is a code snippet of what I am currently doing:
UINT ProcessThisConnection(LPVOID pVoidReceiveSocketInfo)
{
CSocketInfo* pReceiveSocketInfo =3D
(CSocketInfo*)pVoidReceiveSocketInfo;
IData m_Data;
[more code snipped]
VERIFY(m_Data.CreateDispatch("OleServer.Data")=3D=3DTRUE);
sOutBoundTCP=3Dm_Data.ProcessData("TESTING");
m_Data.ReleaseDispatch();
[more code snipped]
}
Jeremiah Talkar -- jtalkar@optika.com
Thursday, February 20, 1997
[Mini-digest: 2 responses]
Try calling AfxOleInit() for each thread before accessing the OLE
sub-system.
Jeremiah
-----Original Message-----
From: fignet05.darrins@eds.com
Sent: Wednesday, February 19, 1997 2:17 PM
To: a
Subject: OLE and Worker Threads.
Environment: VC++ 4.2b NT 4.0 with all patches
I have a multi-threaded application that needs to communicate with
another MFC based application through OLE. When I try to do a
VERIFY(m_Data.CreateDispatch("OleServer.Data")==TRUE); inside the worker
thread I get an assertion failure and the following warning:
CreateDispatch returning scode = CO_E_NOTINITIALIZED ($800401F0).
If I place this code in a non-threaded app or move it outside of the
thread (to my view class for example) everything works fine.
Is there something special that I need to do with CreateDispatch inside a
thread?
Here is a code snippet of what I am currently doing:
UINT ProcessThisConnection(LPVOID pVoidReceiveSocketInfo)
{
CSocketInfo* pReceiveSocketInfo =
(CSocketInfo*)pVoidReceiveSocketInfo;
IData m_Data;
[more code snipped]
VERIFY(m_Data.CreateDispatch("OleServer.Data")==TRUE);
sOutBoundTCP=m_Data.ProcessData("TESTING");
m_Data.ReleaseDispatch();
[more code snipped]
}
-----From: Mike Blaszczak
At 14:17 2/19/97 -0500, FIGNET05.DARRINS@eds.com wrote:
>Environment: VC++ 4.2b NT 4.0 with all patches
>I have a multi-threaded application that needs to communicate with
>another MFC based application through OLE. When I try to do a
>VERIFY(m_Data.CreateDispatch("OleServer.Data")==TRUE); inside the worker
>thread I get an assertion failure and the following warning:
>CreateDispatch returning scode = CO_E_NOTINITIALIZED ($800401F0).
>If I place this code in a non-threaded app or move it outside of the
>thread (to my view class for example) everything works fine.
>Is there something special that I need to do with CreateDispatch inside a
>thread?
In Win32, you need to initialize OLE on a per-thread basis. You
get a NOTINITIALIZED error because you've not initialized OLE for your
secondary thread.
.B ekiM
http://www.nwlink.com/~mikeblas/
These words are my own. I do not speak on behalf of Microsoft.
This performance was not lip-synched.
Become an MFC-L member
| Вернуться в корень Архива
|