Tuesday, June 26, 2012

Simple DLL for visual basic 2010 calculator

Steps to make a DLL Calculator

CREATING A DLL

Prerequist: Visual Studio 2010.
1. Open Visual Studio 2010
2. New Project--->  VC++---->MFC DLL
3. Give name to your dll project say "dllsampleadd"
4. OK creates new project
5. Delete all contents in dllsampleadd.cpp
6. Add the following contents:

#include "stdafx.h"
int _stdcall sum(int x , int y)
{
return x+y;
}


7. Open file dllsampleadd.def
8. Update the contents of dllsampleadd.def to

LIBRARY DLLSAMPLEADD

EXPORTS
sum @1








9. Build ---> Build Solution
10. You can see the DLL file 'dllsampleadd.dll' getting created at the Debug folder of your project

 VISUAL BASIC APPLICATION


1. File ---> NewProject --->  Other languages---> Visual Basic--->Windows Forms Application
2. Give name to your dll project say "add"
3. Drag and drop buttons and labels as shown in screenshot
 4. Double click on add button.
5. Make necessary changes to the code associated with add button as given below:

Private Declare Function sum Lib "C:\Users\hari\Documents\Visual Studio 2010\Projects\dllsampleadd\Debug\dllsampleadd.dll" (ByVal x As Int32, ByVal y As Int32) As Int32
    Private Sub Button1_Click() Handles Button1.Click
        Label4.Text = Str(sum(CInt(TextBox1.Text), CInt(TextBox2.Text)))
    End Sub


6. Run your program( Debug---->Start Debugging)
7. Make necessary changes to your dll program and VB program for adding subract, divide, multiply functions to the calculator.

No comments: