Avatar of doront99
doront99 asked on

Threads inside DLL

Dear 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
Editors IDEsSystem Programming

Avatar of undefined
Last Comment
Knut Hunstad

8/22/2022 - Mon
SOLUTION
nonubik

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
doront99

here is an example
CString temp;
		
temp = "search.query(\"";
temp+="Test";
temp+="\", \"ActiveDoc\");";
 
AFExecuteThisScript(pdDoc,(LPCTSTR)temp,NULL);

Open in new window

ASKER
doront99

BTW, I don't believe there is a synchronization problem since the thread has no option to handle any request before it finished.
SOLUTION
DanRollins

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
doront99

I have already the AFX_MANAGE_STATE MACRO on each function.

As for the second paragraph: how can I make the main thread to do something?
Let's say I did the calculation, now how can I tell the main thread to draw it on the screen?

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
nonubik

>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.
ASKER
doront99

I have tried that as well - hooking into the App class of the DLL with BEGIN_MESSAGE_MAP, but with no success.
It seems that the DLL doesn't actually listen to messages / there is no message loop running.

Does a DLL have some kind of a message loop that I can hook into?
DanRollins

My preferred method is to put a timer in the main window (or any window running on the main thread).   Lets say that you have it execute 4 times per second.  In most cases, that's plenty fast enough so that the user thinks he's seeing real-time updates.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER CERTIFIED SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Knut Hunstad

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 :-)