here is an example
Main Topics
Browse All TopicsDear Experts,
I'm an Adobe Acrobat plug-in developer, and I'm stack here with some problem related to DLLs, I would appreciate your help (with points of course... :) ).
The plug-in works as DLL.
Inside that DLL, I'm having a thread I'm creating for some kind of a message loop.
In that thread, when I get signaled, I'm running a function that I have that handles the message.
The problem I have is that in many time this function cause Acrobat to crash.
Now, I know the problem is with Acrobat but I don't have the source of it, and I have to bypass it.
When I'm trying to run the code directly and not inside the thread the code runs with no problems.
My question is: is there any difference in execution for a code that runs inside / outside a dll?
I'm working with Visual Studio 2003 .NET ("c++")
The thread is created with AfxBeginThread
Many thanks,
Doron
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
The most common problem with DLLs in MFC is failure to put
AFX_MANAGE_STATE(AfxGetSta
at
The most common problem with using threads in MFC is to attempt to access CWnd-derived objects from a non-primary thread. Worker threads should do work that is other than window-related. For instance, rather than updating the screen during a long calculation, you should do calculations and update a status variable and have the main thread examine that status periodically to do screen updates.
>Let's say I did the calculation, now how can I tell the main thread to draw it on the screen?
You can define a custom window message that you can handle yourself in the main app window. And after you have done the calculation you may PostMessage(..) to your main window (i.e. handled in the main thread) and there handle the drawing.
If you're still stuck here, let's see if we still can't help you! I think you need to describe your problem a little more in detail for us. After rereading everything, I still can't quite figure out exactly what your setup is here :-)
So, you are making a plugin for Adobe Acrobat. I'm assuming this is done through some well-defined interface Adobe provides for the purpose? Which I'm sure is documented somewhere, if you'll let us know exactly how you're interfacing with Acrobat. Is Acrobat calling your function through some menu command, your plugin starts, calculates something and then updates something on the screen? Or is it hooked into one or more messages in Acrobat, doing something every time a document view is updated e.g.? Or are you trying to get your dll start some calculation while the user is continuing working in Acrobat, wanting the results to be shown as soon as they are ready?
You make a dll. Does this have any user interface of it's own, or is it sending messages to Acrobat when it needs something drawn?
Why do you want a thread in your dll? It seems like you're having some lengthy calculation? Are you trying to achieve progress reporting during calculation? Or do you just want to have your dll wait for the calculation and then show the results?
If it's progress reporting you're looking for, you could have your main dll thread make a signal that you pass on to the worker thread doing the calculation. Then the main dll thread can do a WAIT for any signal from the worker thread (and for the worker thread to finish). The worker thread sets the signal every now and then, letting the main thread update the progress bar or whatever.
What does AFExecuteThisScript do? You haven't shown anything about how this starts the thread or how it calls into Acrobat? It seems like it somehow runs a script to search the current document for the phrase "Test", but I can't see why you want a thread for this? Isn't this just a message to Acrobat to perform a search task?
I hope this list of questions helps you understand what it is I don't understand :-)
Business Accounts
Answer for Membership
by: nonubikPosted on 2009-01-22 at 01:53:54ID: 23437858
It may be a problem of synchronization between the thread you create and the main thread. Or maybe some faulty pointer references. Can you please post some of the code that runs ok "directly' and crashes if run in another thread?