Lns, mfc and atl – Echelon LNS User Manual
Page 344
LNS Programmer's Guide
330
LNS, MFC and ATL
Versions 6.0 and higher of Microsoft Visual C++ offer two ways to import the interfaces
exposed by the LNS Object Server ActiveX Control into an existing project: the MFC
Class Wizard, and the ATL #import statement described in Chapter 4 of this document.
As of LNS Turbo Edition, the legacy MFC wrappers, in the files lcaobjsv.h,
lcaobjsv3.h, and lcaobjsv.cpp, are no longer included with the LNS Application
Developer's Kit. They required the use of many other header files to include LNS
constants, and were difficult to keep synchronized with the LNS Object Server type
library constants. Instead of using the MFC wrappers, the ATL #import statement
described in Chapter 4 of this document should be included in a global header file to
expose the full set of objects, properties, methods, and constants included with LNS.
The ATL #import statement provides a wrapper that is superior to the MFC wrappers.
The wrapper uses ATL smart pointers to directly call the functions of the LNS Object
Server. In addition, the wrappers generated by the ATL #import statement
automatically regenerate whenever the LNS Object Server is updated (i.e. when service
packs or new versions of the software are released). This is unlike the legacy MFC
wrappers, which must be carefully maintained whenever the LNS Object Server is
updated.
NOTE: Although it is not recommended, you can still generate the lcaobjsv.h,
lcaobjsv3.h, and lcaobjsv.cpp files manually, and use the wrapper files generated
by the MFC Class Wizard instead of the new #import statement. For more information
on this, see the Generating the Legacy MFC Class Wrapper Files section later in this
appendix.
You can apply a combination of the two approaches to take advantage of all available
benefits. You can use the wrappers generated by the MFC Class Wizard to handle
events, and use the wrappers generated by the #import statement to implement the
objects, methods and properties of the LNS Object Server. To do so, follow the steps
described in Chapter 4 to import the LNS Object Server Active X Control. Then, to utilize
the smart pointer for the Object Server interface, use the following assignment
statement. In this statement, the m_ObjectServer variable was declared with code
generated by the MFC Class Wizard:
Header:
#import “lcaobjsv.ocx” rename_namespace(“lns”)
Implementation:
lns::_DLcaObjectServerPtr objectServer = m_ObjectServer.GetControlUnknown();
Then you’ll need to use the ATL smart-pointers (i.e. lns::ILcaNetworksPtr for the
Networks collection):
lns::ILcaNetworksPtr networks = objectServer->Networks;
lns::ILcaNetworkPtr network = networks->Item[“mynetwork”];
To only use the ATL wrappers, you need to manually add the code to create an instance
of the LNS Object Server to your application, as well as the framework for the event
handlers. The following example code shows how you could create an instance of the LNS