More you share, more you have!!!

More you share, more you have!!!

Program to implement active DLL in visual basic using C++

Q.Write a program to create Active DLL file in Visual Basic using C++


1. hit.cpp :

Source Code:->

#include "stdafx.h"

#include "math.h"


BOOL APIENTRY DllMain( HANDLE hModule, 

                       DWORD  ul_reason_for_call, 

                       LPVOID lpReserved

)

{

    return TRUE;

}


int _stdcall sum(int x, int y)

{

return (x+y);

}

int _stdcall subt(int x, int y)

{

return (x-y);

}

int _stdcall mul(int x, int y)

{

return (x*y);

}

int _stdcall div1(int x, int y)

{

return (x/y);

}

double _stdcall sin1(double x)

{

return (sin(x));

}

double _stdcall cos1(double x)

{

return (cos(x));

}

int _stdcall pow1(int x,int y)

{

return (pow(x,y));

}

--------------------------------------------------------------------------------------------------------

.def file:

Source Code:->

LIBRARY hit

EXPORTS

sum @ 1

subt @ 2

mul @ 3

div1 @ 4

sin1 @ 5

cos1 @ 6

pow1 @ 7

--------------------------------------------------------------------------------------------------------

Visual basic file:

Source Code:->

Private Declare Function sum Lib "hit.DLL" (ByVal x As Long, ByVal y As Long) As Long

Private Declare Function subt Lib "hit.DLL" (ByVal x As Long, ByVal y As Long) As Long

Private Declare Function mul Lib "hit.DLL" (ByVal x As Long, ByVal y As Long) As Long

Private Declare Function div1 Lib "hit.DLL" (ByVal x As Long, ByVal y As Long) As Long

Private Declare Function sin1 Lib "hit.DLL" (ByVal x As Double) As Double

Private Declare Function cos1 Lib "hit.DLL" (ByVal x As Double) As Double

Private Declare Function pow1 Lib "hit.DLL" (ByVal x As Long, ByVal y As Long) As Long


Private Sub Command1_Click()

Text3.Text = Str(sum(CInt(Text1.Text), CInt(Text2.Text)))

End Sub


Private Sub Command2_Click()

Text3.Text = Str(subt(CInt(Text1.Text), CInt(Text2.Text)))

End Sub


Private Sub Command3_Click()

Text3.Text = Str(mul(CInt(Text1.Text), CInt(Text2.Text)))

End Sub


Private Sub Command4_Click()

Text3.Text = Str(div1(CInt(Text1.Text), CInt(Text2.Text)))

End Sub


Private Sub Command5_Click()

Text3.Text = Str(sin1(CDbl(Text1.Text)))

End Sub


Private Sub Command6_Click()

Text3.Text = Str(cos1(CDbl(Text1.Text)))

End Sub


Private Sub Command7_Click()

Text3.Text = Str(pow1(CInt(Text1.Text), CInt(Text2.Text)))

End Sub


Output:->


 






















Source Code->  {provided file should present in that directory or create it}

%{

int ch=0, bl=0, ln=0, wr=0;

%}

%%

[\n] {ln++;wr++;}

[\t] {bl++;wr++;}

[" "] {bl++;wr++;}

[^\n\t] {ch++;}

%%

int main()

{

FILE *fp;

char file[10];

printf("Enter the filename: ");

scanf("%s", file);

yyin=fp;

yylex();

printf("Character=%d\nBlank=%d\nLines=%d\nWords=%d", ch, bl, ln, wr);

return 0;

}

Output ->

$cat > input
Girish rao salanke


$lex p1a.l

$cc lex.yy.c –ll

$./a.out

Enter the filename: input
Character=16
Blank=2
Lines=1
Word=3


Share on Google Plus
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment