Click here to Skip to main content
15,884,298 members
Articles / Desktop Programming / MFC
Article

Login: Automation Client

Rate me:
Please Sign up or sign in to vote.
3.44/5 (9 votes)
4 Sep 2003GPL33 min read 89.2K   2.4K   33   13
An automation client that connects to the automation server for verifying user ID and password.

Introduction:

We have learned what automation is and created a login management automation server. Now it's time to build a client application for that server to be more meaningful. You may be guessing why so much work has been done for just reading and writing a simple database, but now you will understand the benefits of this automation technique.

Once you build an automation server, to incorporate it in any client application, its just a simple task of few minutes. The automation server once built, can be used for different client applications built over different environments, without much changes. This would also isolate the client application from the dirty job of long database programming, creating a middle tier between the client application and your database. Further, if you make changes in the database structure, you will just have to change the automation server on the remote server, leaving the client application on all the machines unchanged. This also provides an easy technique for remote database management through DCOM (Distributed Component Object Model).

Prerequisite:

This tutorial assumes that you are familiar with Visual C++/MFC, COM, Automation and other technologies used in this tutorial like ADO, etc. Though there is no need to understand their underpinnings in great detail, you should at least have a working knowledge of what these underpinnings mean. Most important of all, you should take a glance over the login automation server example.

Implementation:

Now it's time to do some hands with DevStudio. We would create an automation client with the help of the type library created by the automation server example.

  • Create a dialog based MFC project unselecting everything in step 2 of 4 and accepting the default values for everything else.
  • Open the class wizard and create a new class from the type library, browse to the folder where the login.tlb file is located and select it.

    Confirm Classes

  • Include the remotelogin.h file to dialog class implementation.
  • Create the dialog as shown in the figure.

    Confirm Classes

  • Add a member variable m_login of type IRemoteLogin to the dialog class.
  • Add the following lines in the OnInitDialog() member function of the dialog class.
    CoInitialize(NULL);
    if(!m_login.CreateDispatch("Login.CRemoteLogin"))
        AfxMessageBox("Login.CRemoteLogin Not found");
  • Link the buttons with dialog member functions and implement these functions as done in the sample project.
  • Compile the project now, it should compile without any errors and then run it.

Conclusion

Here we have successfully built an automation client that can verify the user ID and password, allowing us to add new user, remove existing user and edit the user information. This client can be easily created in MFC, as you have seen how easy it was to connect to a remote automation server. We can use the remote objects created with the help of the type library, just as other objects created from some other classes. Your valuable suggestions are always welcome, to make this article better.

What Next

Learn how to extend your automation component over network via the use of DCOM, here.

Copyright

This code is provided "as is" with no expressed or implied warranty. You can use and abuse this code without any restriction. If you use this source code in any commercial product, acknowledgment is not required but would be appreciated.

Bibliography:

  • VC++, COM and Beyond.

    Author: Yashavant Kanetkar & Sudesh Saoji.

    ISBN: 81-7635-206-8

    Publisher: BPB Publications.

    User Level: Beginning-Intermediate.

    This book provides an in-depth coverage of cutting edge technologies like Document/View Architecture, OLE, COM, DCOM, ActiveX, Open GL, Printing and Print Previewing, HTML Help System, Programming the disk and Screen Savers.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Software Developer (Senior)
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionGood but What Purpose ??? Pin
kokosan16-Apr-07 6:13
kokosan16-Apr-07 6:13 
AnswerRe: Good but What Purpose ??? Pin
Priyank Bolia16-Apr-07 19:23
Priyank Bolia16-Apr-07 19:23 
Generalhelp Pin
vijin0512-Oct-06 2:22
vijin0512-Oct-06 2:22 
Generalhelp Pin
badboy74127-Jul-05 9:53
badboy74127-Jul-05 9:53 
GeneralRe: help Pin
Priyank Bolia27-Jul-05 18:45
Priyank Bolia27-Jul-05 18:45 
GeneralRe: help Pin
badboy74128-Jul-05 17:43
badboy74128-Jul-05 17:43 
GeneralNot Updating the database Pin
Anand Kumar30-Sep-03 0:21
Anand Kumar30-Sep-03 0:21 
GeneralRe: Not Updating the database Pin
Priyank Bolia3-Oct-03 4:19
Priyank Bolia3-Oct-03 4:19 
Generalerror while running the client application Pin
ananymous21-Sep-03 21:21
ananymous21-Sep-03 21:21 
GeneralRe: error while running the client application Pin
Priyank Bolia23-Sep-03 20:01
Priyank Bolia23-Sep-03 20:01 
Questiondatabase location ? Pin
JOHN1131-Aug-03 0:12
JOHN1131-Aug-03 0:12 
AnswerRe: database location ? Pin
Priyank Bolia31-Aug-03 21:09
Priyank Bolia31-Aug-03 21:09 
AnswerRe: database location ? Pin
Anonymous8-Nov-03 18:17
Anonymous8-Nov-03 18:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.