The information in this article applies to:
SUMMARY
Although there may be several ways to implement communication between two
executables, this sample illustrates a simple way a server and a client
application can communicate using IDispatch interfaces. This may not be the
best method, but it is straight forward to implement. Using dual interfaces
may provide a better solution, however.
http://www.microsoft.com/downloads/search.aspand then click How to use the Microsoft Download Center. NOTE: Use the -d option when running Dispcom.exe to decompress the file and recreate the proper directory structure. MORE INFORMATION
The GENERAT.EXE local server generates and displays random colors. It can
either generate one color each time as it is requested, or it can
continuously generate colors in response to a WM_TIMER message. The
GENERAT.EXE server can run either stand-alone or it can be controlled by a
client (in this case the GENCLNT.EXE application). In either case, the
server will be visible, and the server's user interface will be active.
This means the client and the server will need to communicate with each
other to keep the user interface of the client and server synchronized and
to process requests from the other.
The client starts the server via CreateDispatch and thus obtains the IDispatch pointer of the server. Once the client has the server's IDispatch pointer, it can call this method in the server sending its own IDispatch pointer. At this point, two-way communication is possible between the client and the server.
Called by the client to tell the server to release the IDispatch pointer of the client. BOOL AnimateColors(); Called by the client to request that the server generate colors in response to WM_TIMER messages.
Called by the client to request that the server generate a single new color. GENCLNT.EXE methods:
Called by the server when Animate Colors is chosen via the server user interface. This keeps the Animate Colors menu choice of the client synchronized with that of the server.
Called by the server when a color is generated. Called regardless of whether the color was requested by the client or the server. Note: In order to compile this sample under VC 4.0 and later it will be necessary to replace the following code from generat.cpp: Replace:
CDocTemplate* pTemplate = (CDocTemplate*)AfxGetApp()-> m_templateList.GetNext(pos); ASSERT(pTemplate->IsKindOf(RUNTIME_CLASS(CDocTemplate))); With:
CDocTemplate* pTemplate = (CDocTemplate*)AfxGetApp()-> GetNextDocTemplate(pos); ASSERT(pTemplate->IsKindOf(RUNTIME_CLASS(CDocTemplate))); REFERENCES
For information about the necessity of calling AddRef on an IDispatch
pointer passed across process boundaries, please see the following article
in the Microsoft Knowledge Base:
Additional query words: 1.50 1.51 1.52 1.52b 2.00 2.10 2.20 2.50 2.51 2.52 2.52b 3.00 3.10 3.20 4.00 4.10 softlib
Keywords : kbcode kbfile kbole kbsample kbMFC kbVC |
Last Reviewed: January 31, 2000 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |