473,399 Members | 3,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

how to create a thread and a modal dialog from a regular dll?

Hi, there,

I have a multi-threaded non-MFC program that will include a regular dll
which would be part of the user interface, possibly a dialog based interface.
I would prefer to have the user interface dll run on its own thread. How to
do that? I can't find the answer from the msdn knowledge base.

Thanks a lot in advance!

Kate
Nov 17 '05 #1
4 3154
On Fri, 3 Jun 2005 09:16:06 -0700, "MechSoft"
<me******@discussions.microsoft.com> wrote:
Hi, there,

I have a multi-threaded non-MFC program that will include a regular dll
which would be part of the user interface, possibly a dialog based interface.
I would prefer to have the user interface dll run on its own thread. How to
do that? I can't find the answer from the msdn knowledge base.


Threads and DLLs are separate things; a DLL can start a thread, and a
program can call DLL routines from different threads.

If I understand what you want to do, it's probably to call a routine
in the DLL -- StartMyDllUserInterface(), for instance -- and within
that, begin the thread (_beginthreadex) to handle the UI for your DLL.

Note that the thread will require its own message loop, and be careful
not to update UI elements from multiple threads (this causes
deadlocks).

Communication back to the main program will depend on what it expects,
and whether you're in control of how this works. I would need more
details to give definite advice.

Also, you may end up with a confusing interface if you expect things
like keyboard focus, etc., to work well between the main program and
your separate UI thread.

--
Phillip Crews aka Severian
Microsoft MVP, Windows SDK
Posting email address is real, but please post replies on the newsgroup.
Nov 17 '05 #2
Thank you very much for your prompt response. It is very helpful to me.

Yes, my user interface dll will export a function to the application so that
the application can call it to launch the interface. In the function, as you
named, StartMyDllUserInterface(MyInterfaceClass*), the appplication will pass
a pointer which contains all functions that the UI dll needs to communicate
with the application. Most communications are one-way from the interface to
the application. The application is like a database to the UI. The interface
Dll will also export another function to allow the application to inform the
UI of data changes.

With the helpful information from your response, I think I need to create a
user-interface thread from the exported function "StartMyDllUserInterface". I
am going to look more to figure out the details. Any advice will be
appreciated.

Kate

"Severian [MVP]" wrote:
On Fri, 3 Jun 2005 09:16:06 -0700, "MechSoft"
<me******@discussions.microsoft.com> wrote:
Hi, there,

I have a multi-threaded non-MFC program that will include a regular dll
which would be part of the user interface, possibly a dialog based interface.
I would prefer to have the user interface dll run on its own thread. How to
do that? I can't find the answer from the msdn knowledge base.


Threads and DLLs are separate things; a DLL can start a thread, and a
program can call DLL routines from different threads.

If I understand what you want to do, it's probably to call a routine
in the DLL -- StartMyDllUserInterface(), for instance -- and within
that, begin the thread (_beginthreadex) to handle the UI for your DLL.

Note that the thread will require its own message loop, and be careful
not to update UI elements from multiple threads (this causes
deadlocks).

Communication back to the main program will depend on what it expects,
and whether you're in control of how this works. I would need more
details to give definite advice.

Also, you may end up with a confusing interface if you expect things
like keyboard focus, etc., to work well between the main program and
your separate UI thread.

--
Phillip Crews aka Severian
Microsoft MVP, Windows SDK
Posting email address is real, but please post replies on the newsgroup.

Nov 17 '05 #3
On Fri, 3 Jun 2005 11:24:04 -0700, "MechSoft"
<me******@discussions.microsoft.com> wrote:
"Severian [MVP]" wrote:
On Fri, 3 Jun 2005 09:16:06 -0700, "MechSoft"
<me******@discussions.microsoft.com> wrote:
>Hi, there,
>
>I have a multi-threaded non-MFC program that will include a regular dll
>which would be part of the user interface, possibly a dialog based interface.
>I would prefer to have the user interface dll run on its own thread. How to
>do that? I can't find the answer from the msdn knowledge base.
Threads and DLLs are separate things; a DLL can start a thread, and a
program can call DLL routines from different threads.

If I understand what you want to do, it's probably to call a routine
in the DLL -- StartMyDllUserInterface(), for instance -- and within
that, begin the thread (_beginthreadex) to handle the UI for your DLL.

Note that the thread will require its own message loop, and be careful
not to update UI elements from multiple threads (this causes
deadlocks).

Communication back to the main program will depend on what it expects,
and whether you're in control of how this works. I would need more
details to give definite advice.

Also, you may end up with a confusing interface if you expect things
like keyboard focus, etc., to work well between the main program and
your separate UI thread.


Thank you very much for your prompt response. It is very helpful to me.


You're quite welcome.
Yes, my user interface dll will export a function to the application so that
the application can call it to launch the interface. In the function, as you
named, StartMyDllUserInterface(MyInterfaceClass*), the appplication will pass
a pointer which contains all functions that the UI dll needs to communicate
with the application. Most communications are one-way from the interface to
the application. The application is like a database to the UI.
Be aware that callbacks to the application will be done in the context
of your thread! This may have unusual consequences unless the
application is carefully designed and written to handle calls from
arbitrary threads.
The interface
Dll will also export another function to allow the application to inform the
UI of data changes.
Since this function will be called from a different thread than the UI
thread, it should only post messages to the UI thread or UI windows.
It should not use SendMessage or any UI call that implies SendMessage
(i.e., SetWindowText, SetDlgItemText). Otherwise, you could have two
threads updating the same UI, which is dangerous and often causes
deadlocks.
With the helpful information from your response, I think I need to create a
user-interface thread from the exported function "StartMyDllUserInterface". I
am going to look more to figure out the details. Any advice will be
appreciated.


Your UI thread will probably look much like WinMain(); it will need to
create a window (or dialog box) and start a message loop.

If the main application also has a user interface, you may need to
become familiar with such calls as AttachThreadInput(). Here are some
articles that may help:

http://support.microsoft.com/default...kb;en-us;90975
http://support.microsoft.com/default...kb;en-us;97925

and especially:

http://msdn.microsoft.com/library/de...sdn_winthr.asp
--
Phillip Crews aka Severian
Microsoft MVP, Windows SDK
Posting email address is real, but please post replies on the newsgroup.
Nov 17 '05 #4
Thank you! Those references are very good readings. I have learnt quite a lot
today! And I have been able to display a dialog box already from the dll.
Thanks again,

Kate

"Severian [MVP]" wrote:
On Fri, 3 Jun 2005 11:24:04 -0700, "MechSoft"
<me******@discussions.microsoft.com> wrote:
"Severian [MVP]" wrote:
On Fri, 3 Jun 2005 09:16:06 -0700, "MechSoft"
<me******@discussions.microsoft.com> wrote:

>Hi, there,
>
>I have a multi-threaded non-MFC program that will include a regular dll
>which would be part of the user interface, possibly a dialog based interface.
>I would prefer to have the user interface dll run on its own thread. How to
>do that? I can't find the answer from the msdn knowledge base.

Threads and DLLs are separate things; a DLL can start a thread, and a
program can call DLL routines from different threads.

If I understand what you want to do, it's probably to call a routine
in the DLL -- StartMyDllUserInterface(), for instance -- and within
that, begin the thread (_beginthreadex) to handle the UI for your DLL.

Note that the thread will require its own message loop, and be careful
not to update UI elements from multiple threads (this causes
deadlocks).

Communication back to the main program will depend on what it expects,
and whether you're in control of how this works. I would need more
details to give definite advice.

Also, you may end up with a confusing interface if you expect things
like keyboard focus, etc., to work well between the main program and
your separate UI thread.


Thank you very much for your prompt response. It is very helpful to me.


You're quite welcome.
Yes, my user interface dll will export a function to the application so that
the application can call it to launch the interface. In the function, as you
named, StartMyDllUserInterface(MyInterfaceClass*), the appplication will pass
a pointer which contains all functions that the UI dll needs to communicate
with the application. Most communications are one-way from the interface to
the application. The application is like a database to the UI.


Be aware that callbacks to the application will be done in the context
of your thread! This may have unusual consequences unless the
application is carefully designed and written to handle calls from
arbitrary threads.
The interface
Dll will also export another function to allow the application to inform the
UI of data changes.


Since this function will be called from a different thread than the UI
thread, it should only post messages to the UI thread or UI windows.
It should not use SendMessage or any UI call that implies SendMessage
(i.e., SetWindowText, SetDlgItemText). Otherwise, you could have two
threads updating the same UI, which is dangerous and often causes
deadlocks.
With the helpful information from your response, I think I need to create a
user-interface thread from the exported function "StartMyDllUserInterface". I
am going to look more to figure out the details. Any advice will be
appreciated.


Your UI thread will probably look much like WinMain(); it will need to
create a window (or dialog box) and start a message loop.

If the main application also has a user interface, you may need to
become familiar with such calls as AttachThreadInput(). Here are some
articles that may help:

http://support.microsoft.com/default...kb;en-us;90975
http://support.microsoft.com/default...kb;en-us;97925

and especially:

http://msdn.microsoft.com/library/de...sdn_winthr.asp
--
Phillip Crews aka Severian
Microsoft MVP, Windows SDK
Posting email address is real, but please post replies on the newsgroup.

Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ajay | last post by:
hi! my application consists of a GUI with a number of functions. One of these runs a server in a separate thread. the thread is started and given the function start_server to execute the...
2
by: Gilles T. | last post by:
Hi, How I can refresh a modal dialog in asp.net? I open a modal dialog in first with a dropdownlist. To add a element in my dropdownlist (table), I open a second modal dialog to ask element and...
3
by: Andrew Baker | last post by:
OK this has me perplexed, puzzled and bamboozled! I have a remoting service which I displayed a message box in. I then wondered what would happen if a client made a call to the service while the...
10
by: Guadala Harry | last post by:
I have a modal dialog that currently does all of the following except item 4. 1. lets users select a graphic from a list of thumbnails (and when selected, displays the full-size image in a...
6
by: Dennis | last post by:
I have a question about thread safety in a VB application written using Visual Studio.Net 2003. Here is the situation... I am running a process thread in a modal dialog. I have written it so...
3
by: mccoyn | last post by:
When I have a long process to run I can create a new thread to run it and create a modal dialog on my GUI thread. The modal dialog prevents any messages (like button clicks) from working on my...
0
by: dattaforit | last post by:
Hello Friends, I am using VC++ 2005. I have an application for C#. In this application i want to display a modal dialog box or a modal form in a thread. I have on thread running and in that...
1
xarzu
by: xarzu | last post by:
I have a message that comes from a seperate thread of execution that I want to impact a dialog box already on the screen. The dialog box is modal but I believe it would not make any difference if...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.