Click here to Skip to main content
13,349,033 members (67,285 online)
Click here to Skip to main content
Add your own
alternative version


18 bookmarked
Posted 10 Jul 2004

COM Calculator

, 31 Jul 2004
Rate this:
Please Sign up or sign in to vote.
This simple program, which I develop for my understanding. This may help you for understanding the com coding and using it VB
<!-- Download Links --> <!-- Article image --> <!-- Add the rest of your HTML here -->


This article holds information about how to write Com program in VC++ and using it VB. Know the importance of building COM components, a program written in one language should be usable through another. That was an elusive dream in a not too distant part. Then Microsoft unveiled COM. And the once elusive dream started becoming a reality. COM revolutionizes the way software is built. COM is powerful and if you want to remain on the cutting edge of technology, COM is the Way to go. This simple program, This may help you for understanding the COM coding and using it in VB


To make it easy programming in COM. Just go through Inside COM and take a look of this program.

The component which I had designed for sample calculator in VC++. In which we can able to do the simple calculation, I had include Binary and Decimal number conversion.

Source code Guidelines

After creating to the ATL object in COM, you insert ATL Dialog and design it. Add the Clicked event to the Button and write the code part of the program.

Coding for Bin numbers :

<PRE lang=VC++>LRESULT OnClickedButton_Bin(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) { int r[10]={0},i=0,tot=0; int ip=GetDlgItemInt(IDC_EDIT1); do { r[i++]=ip%2; ip=ip/2; tot++; }while(ip>=2); r[i]=ip; int n=0; for(int x=tot;x>=0;x--) { n=(n*10)+r[x]; } SetDlgItemInt(IDC_EDIT1,n); return 0; }

Sample coding for the display number One

<PRE lang=VC++>LRESULT OnClickedButton1(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) { int n1=GetDlgItemInt(IDC_EDIT1); n1=(n1*10)+1; SetDlgItemInt(IDC_EDIT1,n1); return 0; }

Coding for after pressing the equal button :

<PRE lang=VC++>LRESULT OnClickedButton_Eqa(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) { int n2=GetDlgItemInt(IDC_EDIT1); switch(opt) { case '+': r=n1+n2; break; case '-': r=n1-n2; break; case '*': r=n1*n2; break; case '/': r=n1/n2; break; case '^': r=pow(n1,n2); break; default: SetDlgItemInt(IDC_EDIT1,0); } SetDlgItemInt(IDC_EDIT1,r); return 0; }

Coding for 1/X calculation :

<PRE lang=VC++>LRESULT OnClickedButton_OneByX(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) { n1=GetDlgItemInt(IDC_EDIT1); s.Format("%f",(1.0/n1)); SetDlgItemText(IDC_EDIT1,s); return 0; }

Coding for Dec number :

<PRE lang=VC++>LRESULT OnClickedButton_Dec(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) { char bin[100]; int dec=0,temp,cont=0; n1=GetDlgItemInt(IDC_EDIT1); s.Format("%d",n1); strcpy(bin,s); int totlen=strlen(bin)-1; while(totlen>=0) { if(bin[totlen]=='0') temp=pow(2,cont)*0; else if(bin[totlen]=='1') temp=pow(2,cont)*1; dec=dec+temp; totlen--; cont++; } SetDlgItemInt(IDC_EDIT1,dec); return 0; }

After completing the coding part just Build the program. The component is created. After that open the VB insert completing in the program where your need.

1st Step in VB

2nd Step in VB

Without any coding part for calculator your can able to the proper output in the form of VB program.

This is first step which I kept in COM. which lead me to learn more in this subject. So keep trying until you succeed in COM


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
India India
I am baladevan programmer in VC++ ATL COM for Software Company based in Trichy, India.
I am B.E (Comp Sci.)

You may also be interested in...

Comments and Discussions

GeneralDejavu Pin
Jubjub11-Jul-04 12:24
memberJubjub11-Jul-04 12:24 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180111.1 | Last Updated 1 Aug 2004
Article Copyright 2004 by sbaladevan
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid