Posts

Complex class C++ Example

Define a complex class, define default constructor, parameterized constructors, copy constructor, destructor. Overload +, -, unary -, ++ (prefix, postfix), =, comma (,), ->, << and >> operators. #include<iostream> using namespace std; #include<math.h> //defining the complex class class complex { //private members float real; float img; //publc members public: //constructors are used to initialize the objects //default constructor complex() { real=0; img=0; } //parameterized constructor complex(float a,float b) { real=a; img=b; } //copy constructor complex(const complex &c) { real=c.real; img=c.img; } //destructors is used to deallocate the data stored ~complex() { cout<<"destroyed"; } void get_complex() { cout<<"\n enter the real value"; cin>>real; cout<<"\n enter the imaginary value:"; cin>...

Polar Class Example C++

Define polar class where each object represents point in polar coordinates (angle and radius). Include static data member which keeps track the number of active objects of the class #include<iostream> #include<math.h> using namespace std; class polar { float real; float img; public: static int count; void get_polar() { count++; cin>>real>>img; } void print_polar() { cout<<real<<img; } polar() { count++; real=img=0; } polar(const polar &p1) { count++; img=p1.img; real=p1.real; } ~polar() { count--; cout<<"DESTRUCTOR\n"; } }; int polar::count; int main() { polar c1,c2,c3,c4; c1.get_polar(); c2.get_polar(); c3.get_polar(); c4.get_polar(); cout<<polar::count; c1.~polar(); c2.~polar(); c3.~polar(); c4.~polar(); return 0; }

Point Class Example C++

Define a point class, where each object represents point in Cartesian coordinates (x, y). Define objects of this class and calculate the distance between the 2 points through a friend function #include<iostream> #include<math.h> using namespace std; class point { float x; float y; public: point() { x=0; y=0; } point(int z) { x=y=z; } point(int a,int b) { x=a; y=b; } point(const point &c) { x=c.x; y=c.y; } void get_point() { cin>>x>>y; } void print_point() { cout<<x<<y; cout<<"\n"; } friend float dist_point(point p1,point p2); }; float dist_point(point p1,point p2) { float result; result=sqrt(((p2.x-p1.x)*(p2.x-p1.x))+((p2.y-p1.y)*(p2.y-p1.y))); return result; } int main() { point c,c1,c2,c3; float distance; c.print_point(); c1.print_point(); c2.print_point(); c3.print_point(); c.get_point(); c1...

msinfo32 utility tutorial

msinfo stands for Microsoft System Information . You can start msinfo32 in two ways: Method 1: Start -> All Programs -> Accessories -> System Tools -> System Information Method 2: Start -> Run -> Type msinfo32 -> Click OK Location:  C:\Windows\System32\msinfo32.exe What you can do with msinfo32 utility? --> Know what device drivers are loaded in computer. --> Devices present in the system --> Diagnose computer issues. --> BIOS Version --> Windows Version --> OEM System Information (Manufacturer, Model,type) --> Type of CPU --> Amount of Memory --> User Name (Format: DomainName\UserName) --> Time Zone --> Boot Device --> Locale This information can be saved into a file (Format *,nfo) which can be opened only by msinfo utility. In order to save the information Click File -> Save and enter the name.

Windows CE:Accessing a Stream Driver from an Application

#include "stdafx.h" #include <Windows.h> #include <WinBase.h> int _tmain(int argc, TCHAR *argv[], TCHAR *envp[]) {     HANDLE ret_device = ActivateDeviceEx(L"\\Drivers\\StreamTestDrv" , NULL,0, NULL);     if (ret_device == INVALID_HANDLE_VALUE)     {         printf("Invalid Handle\n");      }      else      {         printf("Valid Handle\n");      }     HANDLE fileptr = CreateFile(L"DRV1:",                                                      GENERIC_READ|GENERIC_WRITE,                                                      FILE_SHARE_READ | FILE_SHARE_WRITE...

Windows CE : Accessing Registry From your Driver

If you know a particular a registry key name then reading the value of the key can be done by using RegQueryValueEx function. Passing NULL as the fifth argument will return the length then you can allocate a bu er of that length and pass the pointer of it. Suppose I have added a key value pair in platform.reg as shown below: "Dll"="StreamTestDrv.dll" "Order"=dword:1 "Index"=dword:1 "Prefix"="DRV" "Flags"=dword:0010 ; User Mode: 0010 means DEVFLAGS_LOAD_AS_USERPROC "DisplayName"="User Mode Driver" In order to access the value of the key "DisplayName", Modify the DRV_Init function which was written in the previous post DWORD DRV_Init(LPCTSTR pContext, LPCVOID lpcContext) {     HKEY hkey;     ULONG ktype;     char kvalue[100];     DWORD klength = sizeof(kvalue);     RETAILMSG(TRUE, (TEXT("DRV Driver:DD_Init:%s\n"), pContext));     hkey = OpenDeviceKey(pConte...

Dumpbin Utility Tutorial

dumpbin is a program in Visual Studio Tools that helps you to display information in binary fi le. By using dumpbin we can check whether a dll is build for  x86 or x64. In order to run it Go to Start -> Microsoft Visual Studio2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt. Type dumpbin and it will list all the commands present. To see all the methods exported by a particular DLL, change the directory where the DLL is present and type the following command: dumpbin /exports TestStreamDrv.dll To check whether a dll is build for x86 or x64 and type the following command: dumpbin /headers TestStreamDrv.dll It displays a lot of information. Look for Machine which is present in FILE HEADER VALUES . This determines whether the DLL is present for x86 or x64. References: http://thompsonng.blogspot.com/2011/03/dumpbin-checking-your-application.html