Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 380
  • Last Modified:

Can't use ocx control in secondary thread

Hi, need some help here. I can't seem to use any ocx control (such as grid32 and crystal report control) when they are used in secondary threads.
If I use them in my main application no problem. The problem occurs when I post a thread message (using PostThreadMessage) to another user interface thread (derived using CWinThread, and is in another mfc externison dll). The dialog box that
consists the control will appear but will then crash out with access violation exception after the dialog box is closed.
The msdn knowledge base noted that this is a bug in ver 4.1 of visual c, but visual 4.2b should work. Anyone has any solution here? Thanks a lot.

Regards
Boon Tien Ng

0
boontien
Asked:
boontien
1 Solution
 
jasiekCommented:
I can put here my remark. First of all I always have problems using PostThreadMessage(). Use global variables to transfer data between threads and it will work. Second, if you have access violation on closing window, that means some work in destruction of this window was done by you, and some by MFC. And there is a conflict. I do not know how you create this window, but maybe you should use pointers instead of objects, create objects and delete them explicitly. Use Destroy() on window objects.
Regards,
0
 
dabblerCommented:
Make sure you're initializing OLE from each thread you're using it in.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now