JrnlPost Sample (Accessing Business Logic from Both COM and .NET Framework Clients)
This sample creates a single DLL containing native business logic, an interface and type library for COM clients, and an assembly with corresponding metadata for .NET Framework clients. Clients written in Visual J# and Managed Extensions for C++ are used to access the business logic.
This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.
Building and Running the Sample
To open the sample file in Solution Explorer
Click Download Sample.
The File Download message box appears.
Click Open, and on the left column of the zip folder window, click Extract all files.
The Extraction Wizard opens.
Click Next. You can change the directory that the files will be extracted to, and then click Next again.
Make sure that the Show extracted files check box is selected, and click Finish.
Double-click the sample's .sln file.
The sample solution is displayed in Solution Explorer. You might get a security warning that says the solution location is not trusted. Click OK to continue.
To build this sample
On the Build menu, click Build Solution.
In Solution Explorer, right-click the JrnlPost solution, and on the shortcut menu, click Build Solution.
To run this sample
In Solution Explorer, right-click the comJrnlClient project.
On the shortcut menu, click Debug, then click Start new instance.
Repeat steps 1 and 2 with the netJrnlClientA and netJrnlClientB projects.
Once the clients have started, a series of dialog boxes (with an OK button) appear, notifying you of calls into the business logic. Close the dialog boxes by clicking the OK button.
To get more information on the interaction between components, step through the code by either setting breakpoints or using the Debug menu to step into or over the sample code.
The main focus of the sample is accessing business logic from both COM and .NET Framework clients and not on implementation of the business logic itself. Therefore, the business logic in this sample is relatively uninteresting. In fact, the business logic does minimal validation and shows Win32 message boxes corresponding to server business actions to illustrate steps. The JEPost class, which implements the business logic, is defined and implemented in JEPost.h and JEPost.cpp, respectively.
The class implementing the COM component contains a pointer to an instance of the business logic class. The COM component can be thought of as the wiring through which a COM client accesses the underlying business logic. JrnlPost.dll contains a type library that COM clients consume to discover the interfaces and methods exposed by the COM component. The COM client in this sample uses the compiler's #import feature to consume a type library and generate a smart pointer that is then used by the client to instantiate and call into the COM component. The class implementing the COM component is comJEPost, which is defined and implemented in comJEPost.h and comJEPost.cpp, respectively.
The class implementing the .NET Framework component also contains a pointer to an instance of the business logic class. Much like its COM counterpart, the .NET Framework component in this sample can be thought of as the wiring through which a .NET Framework client accesses the underlying business logic. JrnlPost.dll contains a single file assembly with corresponding metadata that .NET Framework clients consume to discover and access the public classes and methods exposed by the .NET Framework component. The class implementing the .NET Framework component is netJEPost, which is defined and implemented in netJEPost.h and netJEPost.cpp, respectively.
There are three client projects in this sample:
ComJrnlClient, a COM client implemented in native C++.
NetJrnlClientA, a .NET Framework client written in Visual J# .
NetJrnlClientB, a client written using Managed Extensions for C++.