13,002,628 members (63,147 online)
alternative version

#### Stats

37.9K views
18 bookmarked
Posted 10 Jul 2004

# COM Calculator

, 31 Jul 2004
 Rate this:
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 -->

## IMPORTANT

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

## Introduction

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.

## 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
I am baladevan programmer in VC++ ATL COM for Software Company based in Trichy, India.
I am B.E (Comp Sci.)

## Comments and Discussions

 First Prev Next
 My vote of 5 manoj kumar choubey28-Feb-12 18:08 manoj kumar choubey 28-Feb-12 18:08
 I don't see the images on this site Hoornet@Job28-Jul-04 22:31 Hoornet@Job 28-Jul-04 22:31
 Dejavu Jubjub11-Jul-04 11:24 Jubjub 11-Jul-04 11:24
 Last Visit: 31-Dec-99 18:00     Last Update: 26-Jun-17 20:34 Refresh 1

General    News    Suggestion    Question    Bug    Answer    Joke    Praise    Rant    Admin

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