?? sh.htm
字號:
<BODY>
<CENTER><H3><FONT COLOR="#a0a099">
Making
Multiple Instances of an Application run in the Same Process
Space
</FONT></H3></CENTER><HR>
<!-- Author and contact details -->This
article was contributed by <A href="mailto:ramakrsna@hotmail.com">V. <U><FONT
color=#0000ff>Rama Krishna</FONT></U>.
<!-- Sample image - gif or jpg -->
</A>
<P>If you are familiar with Internet Explorer 4.0 you would find that in the
Advanced Internet Settings there is an option "Browse in a New
Process". If you uncheck this check box and run IExplorer.exe and then
start task manager (or Process Viewer) you would find that there is no IExplorer
in the processes yet the Internet Explorer appears. Checking "Browse in a
new process" and starting Internet Explorer runs it as IExplorer.exe again.
</P>
<P>In the first case instead of a separate process being created for Internet
Explorer a thread is created in explorer.exe and instances of Internet Explorer
run in different threads within the process space of explorer.exe. Recently, I
also found the need to do the same in my application. This article demonstrates
how this could be achieved.</P>
<P>This is partcularly useful when lots of data need to be shared among
instances of applications. Typically the first instance of the application loads
data from the disk file or initializes through other methods and this data needs
to be more or less constant throughout the application. Memory mapped file is
obviously an alternative but it requires quite a bit of pointer arithmetic and
to a lot of extent convenience is lost.This alternative is convinient but has
certain risks associated like if a single instance of the application crashes
then all the instances are gone.</P>
<H4>Implementation</H4>
<P>Coming to the implementation, it's quite simple. Any instance of the
application launched either through explorer or through API calls such as
CreateProcess, first detects if a window of a particular class exists, if it
doesnot it creates one. If the window does exists the newly created process
simple sends a message to the window and transfers the control to the other
running instance. The already running instance of the application launches a
separate thread that encapsulates an instance of an application like creating
the window etc.</P>
<PRE><TT><FONT COLOR="#990000">
[Any source code goes here]
<!-- end the block of source code -->
</FONT></TT></PRE>
<!-- create more blocks of source code as needed -->
<!-- demo project -->
<p><A HREF="[demo project zip file name here]">Download demo project - [size in KB] KB</A>
<!-- Zipped source -->
<p><A HREF="[source code zip file name here]">Download source - [size in KB] KB</A>
<!-- Posted / Update date Month day, year (eg August 11, 1998) - add to the list -->
<p>Date Posted: August 11, 1998
<!--#include virtual="footer.shtml" --></p></BODY></HTML>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -