Click here to Skip to main content
15,891,375 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
QuestionBitmap image in static control is flicker Pin
am 20093-Nov-09 22:15
am 20093-Nov-09 22:15 
Questionstd::copy question [modified] Pin
followait3-Nov-09 14:33
followait3-Nov-09 14:33 
AnswerRe: std::copy question Pin
Stuart Dootson3-Nov-09 23:40
professionalStuart Dootson3-Nov-09 23:40 
GeneralRe: std::copy question Pin
followait4-Nov-09 3:17
followait4-Nov-09 3:17 
QuestionHow to use WTL8 Wizard in VC6.0 ? Pin
wangningyu1-Nov-09 4:11
wangningyu1-Nov-09 4:11 
AnswerRe: How to use WTL8 Wizard in VC6.0 ? Pin
Stuart Dootson2-Nov-09 21:23
professionalStuart Dootson2-Nov-09 21:23 
GeneralRe: How to use WTL8 Wizard in VC6.0 ? Pin
wangningyu3-Nov-09 3:42
wangningyu3-Nov-09 3:42 
QuestionFiring a COM Event From Another Thread Pin
Rob Caldecott29-Oct-09 10:50
Rob Caldecott29-Oct-09 10:50 
I have created an in-process COM object (DLL) using ATL. Note that this is an object and not a control (so has no window or user-interface.) My problem is that I am trying to fire an event from a second thread and I am getting a Catastrophic failure (0x8000FFFF). If I fire the event from my main thread, then I don't get the error. The second thread is calling CoInitializeEx but this makes no difference. I am using the Apartment threading model but switching to Free Threaded doesn't appear to help.

The fact I am trying to do this from a second thread is obviously crucial. Is there an easy way to do this?

For example, in my main object's source file:

STDMETHODIMP MyObject::SomeMethod(...)
{
  CreateThread(NULL, 0, ThreadProc, this, 0, NULL);
  // Succeeds with S_OK
  FireEvent(L"Hello, world!");
  return S_OK;
}

DWORD WINAPI ThreadProc(LPVOID param)
{
  CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
  MyObject* comObject = reinterpret_cast<MyObject*>(param);
  // Fails with 0x8000FFFF
  comObject->FireEvent(L"Hello, world!");
}

void MyObject::FireEvent(BSTR str)
{
  ...
  // Returns 0x8000FFFF if called from ThreadProc
  // Returns S_OK if called from SomeMethod
  pConnection->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &params, NULL, NULL, NULL);
}


One idea would be for the main COM object class to create a hidden window and pass the window handle to the thread. The thread could then post a message to the window which would then fire the event. This would ensure the right thread is firing the event. The only problem with this is I don't think there is a message pump running in the case of a simple COM object like this (although I might be wrong) and I have no ideas how to implement one (DLLMain? no ideas.)


AnswerRe: Firing a COM Event From Another Thread Pin
Lim Bio Liong1-Nov-09 23:53
Lim Bio Liong1-Nov-09 23:53 
AnswerRe: Firing a COM Event From Another Thread Pin
Roger Stoltz2-Nov-09 5:43
Roger Stoltz2-Nov-09 5:43 
AnswerRe: Firing a COM Event From Another Thread Pin
Lim Bio Liong2-Nov-09 18:50
Lim Bio Liong2-Nov-09 18:50 
QuestionCOM Instantiation. Pin
mh@markhoscik.plus.com29-Oct-09 4:50
mh@markhoscik.plus.com29-Oct-09 4:50 
QuestionHow to implement drived Interface using ATL? Pin
kcynic20-Oct-09 17:10
kcynic20-Oct-09 17:10 
AnswerRe: How to implement drived Interface using ATL? Pin
«_Superman_»21-Oct-09 11:47
professional«_Superman_»21-Oct-09 11:47 
GeneralRe: How to implement drived Interface using ATL? Pin
kcynic22-Oct-09 0:41
kcynic22-Oct-09 0:41 
GeneralRe: How to implement drived Interface using ATL? Pin
Lim Bio Liong4-Nov-09 18:30
Lim Bio Liong4-Nov-09 18:30 
GeneralRe: How to implement drived Interface using ATL? Pin
kcynic4-Nov-09 18:47
kcynic4-Nov-09 18:47 
GeneralRe: How to implement drived Interface using ATL? Pin
Lim Bio Liong4-Nov-09 18:50
Lim Bio Liong4-Nov-09 18:50 
GeneralRe: How to implement drived Interface using ATL? Pin
kcynic4-Nov-09 18:58
kcynic4-Nov-09 18:58 
GeneralRe: How to implement drived Interface using ATL? Pin
Lim Bio Liong4-Nov-09 19:04
Lim Bio Liong4-Nov-09 19:04 
GeneralRe: How to implement drived Interface using ATL? Pin
kcynic4-Nov-09 19:15
kcynic4-Nov-09 19:15 
GeneralRe: How to implement drived Interface using ATL? Pin
Lim Bio Liong4-Nov-09 19:18
Lim Bio Liong4-Nov-09 19:18 
GeneralRe: How to implement drived Interface using ATL? Pin
kcynic4-Nov-09 19:46
kcynic4-Nov-09 19:46 
QuestionIs there any code library available for developing BHOs? Pin
Ziink9-Oct-09 10:44
Ziink9-Oct-09 10:44 
AnswerRe: Is there any code library available for developing BHOs? Pin
«_Superman_»10-Oct-09 10:36
professional«_Superman_»10-Oct-09 10:36 

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.