windows operating environment cs423-cotter1. 2 windows operating environment 64 bit operating...

38
Windows Operating Environment cs423-cotter 1

Upload: colleen-howard

Post on 04-Jan-2016

237 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Windows Operating Environment cs423-cotter1. 2 Windows Operating Environment 64 bit operating environment – Windows 7 Microsoft Visual Studio.net 2010

Windows Operating Environment

cs423-cotter 1

Page 2: Windows Operating Environment cs423-cotter1. 2 Windows Operating Environment 64 bit operating environment – Windows 7 Microsoft Visual Studio.net 2010

cs423-cotter 2

Windows Operating Environment

• 64 bit operating environment – Windows 7• Microsoft Visual Studio.net 2010• STB Rooms 460, 462, 464

– 75 machines – Intel Dual Core class– Personal storage on remote machines

• Q: drive (60 MB), Y: drive (100MB)

– Most programs on local hosts

Page 3: Windows Operating Environment cs423-cotter1. 2 Windows Operating Environment 64 bit operating environment – Windows 7 Microsoft Visual Studio.net 2010

cs423-cotter 3

Windows Operating Environment

• Tools Available on SCE machines:– Web Browsers (Netscape, Explorer)– Business tools (MS Office)– Math tools (Maple, Matlab)– Programming tools ( MSVS2008, etc. )– ftp– telnet– etc.

Page 4: Windows Operating Environment cs423-cotter1. 2 Windows Operating Environment 64 bit operating environment – Windows 7 Microsoft Visual Studio.net 2010

cs423-cotter 4

Find IP Address of W7 Machine

• Start -- Programs -- Command Prompt• Brings up a text window• At text prompt: route print C:\users>route print

Active Routes:

Network Address Netmask Gateway Address Interface Metric 0.0.0.0 0.0.0.0 134.193.2.254 134.193.2.253 1 127.0.0.0 255.0.0.0 127.0.0.1 127.0.0.1 1 134.193.2.0 255.255.255.0 134.193.2.253 134.193.2.253 1 134.193.2.253 255.255.255.255 127.0.0.1 127.0.0.1 1 134.193.255.255 255.255.255.255 134.193.2.253 134.193.2.253 1 224.0.0.0 224.0.0.0 134.193.2.253 134.193.2.253 1 255.255.255.255 255.255.255.255 134.193.2.253 134.193.2.253 1

Page 5: Windows Operating Environment cs423-cotter1. 2 Windows Operating Environment 64 bit operating environment – Windows 7 Microsoft Visual Studio.net 2010

cs423-cotter 5

Using ipconfig:

Q:\>ipconfig

Windows 2000 IP Configuration

Ethernet adapter Local Area Connection:

Connection-specific DNS Suffix . : ddns.umkc.edu IP Address. . . . . . . . . . . . : 134.193.2.253 Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . : 134.193.2.254

Q:\>

Page 6: Windows Operating Environment cs423-cotter1. 2 Windows Operating Environment 64 bit operating environment – Windows 7 Microsoft Visual Studio.net 2010

Windows Programming Environment - MS Dev Studio

cs423-cotter 6

Page 7: Windows Operating Environment cs423-cotter1. 2 Windows Operating Environment 64 bit operating environment – Windows 7 Microsoft Visual Studio.net 2010

Visual Studio .NET

Page 8: Windows Operating Environment cs423-cotter1. 2 Windows Operating Environment 64 bit operating environment – Windows 7 Microsoft Visual Studio.net 2010

Windows ProgrammingStart New Project

• Microsoft Visual Studio .Net• Start -- Programs -- MS Visual Studio -- MS

Visual Studio• To create a new project:

– From Start Page: Create – Project– Select Win32 Console Application– Identify storage location for new project– Provide Project name– OK

cs423-cotter 8

Page 9: Windows Operating Environment cs423-cotter1. 2 Windows Operating Environment 64 bit operating environment – Windows 7 Microsoft Visual Studio.net 2010
Page 10: Windows Operating Environment cs423-cotter1. 2 Windows Operating Environment 64 bit operating environment – Windows 7 Microsoft Visual Studio.net 2010

New Project Window

Page 11: Windows Operating Environment cs423-cotter1. 2 Windows Operating Environment 64 bit operating environment – Windows 7 Microsoft Visual Studio.net 2010

Windows ProgrammingAdd / Create files

• Project – Add Existing Item – C++ File• Locate desired files.• Repeat for all needed files• For new files:• Project -- Add New Item – C++ File• Identify file.

cs423-cotter 11

Page 12: Windows Operating Environment cs423-cotter1. 2 Windows Operating Environment 64 bit operating environment – Windows 7 Microsoft Visual Studio.net 2010
Page 13: Windows Operating Environment cs423-cotter1. 2 Windows Operating Environment 64 bit operating environment – Windows 7 Microsoft Visual Studio.net 2010
Page 14: Windows Operating Environment cs423-cotter1. 2 Windows Operating Environment 64 bit operating environment – Windows 7 Microsoft Visual Studio.net 2010

Windows ProgrammingAdd Libraries

• Project -- Properties• linker tab -- category = Input -- add library

names to “Additional Dependencies”• for sockets, add “wsock32.lib”

cs423-cotter 14

Page 15: Windows Operating Environment cs423-cotter1. 2 Windows Operating Environment 64 bit operating environment – Windows 7 Microsoft Visual Studio.net 2010
Page 16: Windows Operating Environment cs423-cotter1. 2 Windows Operating Environment 64 bit operating environment – Windows 7 Microsoft Visual Studio.net 2010

Add Libraries

Page 17: Windows Operating Environment cs423-cotter1. 2 Windows Operating Environment 64 bit operating environment – Windows 7 Microsoft Visual Studio.net 2010

To support Multi-threaded Programs:

• Select Project Program Properties• Select C/C++ tab

– Code Generation subtab

• Runtime Library item: – Default may be “Single-threaded Debug (/MLd)”– Select “Multi-threaded Debug (/MTd)”

Page 18: Windows Operating Environment cs423-cotter1. 2 Windows Operating Environment 64 bit operating environment – Windows 7 Microsoft Visual Studio.net 2010
Page 19: Windows Operating Environment cs423-cotter1. 2 Windows Operating Environment 64 bit operating environment – Windows 7 Microsoft Visual Studio.net 2010
Page 20: Windows Operating Environment cs423-cotter1. 2 Windows Operating Environment 64 bit operating environment – Windows 7 Microsoft Visual Studio.net 2010

Windows ProgrammingSelect Active Configuration

• Two compile configurations available– Release– Debug

• Build – select “Configuration Manager”• Select either Debug or Release

– Note that debug versions create large (megabyte) files.

cs423-cotter 20

Page 21: Windows Operating Environment cs423-cotter1. 2 Windows Operating Environment 64 bit operating environment – Windows 7 Microsoft Visual Studio.net 2010
Page 22: Windows Operating Environment cs423-cotter1. 2 Windows Operating Environment 64 bit operating environment – Windows 7 Microsoft Visual Studio.net 2010

Active / Debug Configuration

Page 23: Windows Operating Environment cs423-cotter1. 2 Windows Operating Environment 64 bit operating environment – Windows 7 Microsoft Visual Studio.net 2010

Windows ProgrammingBuild and Execute Project

• Build -- Build “project_name”• Check message window for compile and link

status. • If no errors are indicated, execute program.• Debug – “Start Debugging” or “Start Without

Debugging”

cs423-cotter 23

Page 24: Windows Operating Environment cs423-cotter1. 2 Windows Operating Environment 64 bit operating environment – Windows 7 Microsoft Visual Studio.net 2010
Page 25: Windows Operating Environment cs423-cotter1. 2 Windows Operating Environment 64 bit operating environment – Windows 7 Microsoft Visual Studio.net 2010
Page 26: Windows Operating Environment cs423-cotter1. 2 Windows Operating Environment 64 bit operating environment – Windows 7 Microsoft Visual Studio.net 2010

Windows Threads

• Similar in concept to processes, but designed to identify multiple activities that can be scheduled independently.

• All programs have at least 1 thread -- main ( ) program

• Any thread can create new threads.

cs423-cotter 26

Page 27: Windows Operating Environment cs423-cotter1. 2 Windows Operating Environment 64 bit operating environment – Windows 7 Microsoft Visual Studio.net 2010

Windows Threads

• In C language (console mode):

unsigned long _beginthread (void(_cdecl *start_address)(void *),unsigned stack_size,void *arglistv );

Required Header: <process.h>Required Libraries: LIBCMT.LIB or

MSVCRT.LIB

cs423-cotter 27

Page 28: Windows Operating Environment cs423-cotter1. 2 Windows Operating Environment 64 bit operating environment – Windows 7 Microsoft Visual Studio.net 2010

_beginthread ( )

• void(_cdecl *start_address)(void *),– Start address of the routine that will begin the thread– The routine must have no return value

• unsigned stack_size,– Provide either a stack size for new thread or, if value is 0,

use the same stack size as “parent thread” uses.

• void *arglist– Address of data item passed to new thread or NULL if

nothing passed

cs423-cotter 28

Page 29: Windows Operating Environment cs423-cotter1. 2 Windows Operating Environment 64 bit operating environment – Windows 7 Microsoft Visual Studio.net 2010

consum.cpp - multithreading

cs423-cotter 29

#include <stdlib.h>#include <stdio.h>#include <process.h>

void addem(void *);

int main(int argc, char *argv[]){

int number = 4;_beginthread( addem, 0,(void *)&number);number++;addem(&number);return 0;

}

Page 30: Windows Operating Environment cs423-cotter1. 2 Windows Operating Environment 64 bit operating environment – Windows 7 Microsoft Visual Studio.net 2010

consum.cpp - multithreading

cs423-cotter 30

void addem(void * vcount){

int i, count, sum;sum = 0;count = *(int *)vcount;for (i=0; i<=count; ++i) {

printf("The value of i is %d\n", i);fflush(stdout);sum += i;

}printf("The sum is %d\n", sum);fflush(stdout);

}

Page 31: Windows Operating Environment cs423-cotter1. 2 Windows Operating Environment 64 bit operating environment – Windows 7 Microsoft Visual Studio.net 2010

consum.cpp - Results

cs423-cotter 31

The value of i is 0The value of i is 1The value of i is 2The value of i is 3The value of i is 4The value of i is 5The sum is 15

Page 32: Windows Operating Environment cs423-cotter1. 2 Windows Operating Environment 64 bit operating environment – Windows 7 Microsoft Visual Studio.net 2010

consum2.cpp - multithreading

cs423-cotter 32

#include <stdlib.h>#include <stdio.h>#include <process.h>#include <windows.h>

void addem(void *);

int main(int argc, char *argv[]){

int number = 4;_beginthread( addem, 0,(void *)&number);Sleep (100L);number++;addem(&number);return 0;

}

Page 33: Windows Operating Environment cs423-cotter1. 2 Windows Operating Environment 64 bit operating environment – Windows 7 Microsoft Visual Studio.net 2010

consum2.cpp - multithreading

cs423-cotter 33

void addem(void *vcount){

int i, sum, count;count = *(int *)vcount;sum = 0;for (i=0; i<=count; ++i)

{printf("The value of i is %d\n", i);fflush(stdout);sum += i;

}printf("The sum is %d\n", sum);fflush(stdout);

}

Page 34: Windows Operating Environment cs423-cotter1. 2 Windows Operating Environment 64 bit operating environment – Windows 7 Microsoft Visual Studio.net 2010

consum.cpp - Results

cs423-cotter 34

The value of i is 0The value of i is 1The value of i is 2The value of i is 3The value of i is 4The sum is 10The value of i is 0The value of i is 1The value of i is 2The value of i is 3The value of i is 4The value of i is 5The sum is 15

Page 35: Windows Operating Environment cs423-cotter1. 2 Windows Operating Environment 64 bit operating environment – Windows 7 Microsoft Visual Studio.net 2010

consumfloat.cpp #include <windows.h> , <stdlib.h, <stdio.h>, <process.h>

void p_func(void *); int flag;

int main(int argc, char *argv[]){

float num, num2;num = 9.0f;num2 = 12.0f;flag = 0;_beginthread(p_func, 0, (void *)&num);while (flag == 0)

;p_func((void *)&num2);return 0;

}

cs423-cotter 35

Page 36: Windows Operating Environment cs423-cotter1. 2 Windows Operating Environment 64 bit operating environment – Windows 7 Microsoft Visual Studio.net 2010

consumfloat.cppvoid p_func(void * vcount){

float *numptr;int number, i, prod;flag = 1;numptr = (float*) vcount;number = (int) *numptr;prod = 1;for (i = 1; i <= number; i++)

prod = prod * i;printf("The number is %d\n", number);printf ("The factorial product is %d\n", prod);printf("The float is %5.2f\n", *numptr);fflush(stdout);

}cs423-cotter 36

Page 37: Windows Operating Environment cs423-cotter1. 2 Windows Operating Environment 64 bit operating environment – Windows 7 Microsoft Visual Studio.net 2010

Consumfloat.cpp Results

The number is 9The factorial product is 362880The float is 9.00The number is 12The factorial product is 479001600The float is 12.00

Press any key to continue . . .

Page 38: Windows Operating Environment cs423-cotter1. 2 Windows Operating Environment 64 bit operating environment – Windows 7 Microsoft Visual Studio.net 2010

Summary

• Many Windows Integrated Development Environments (IDEs) available to develop C++ programs. – UMKC Labs provide Microsoft Visual Studio

• Multi-threading supported in Windows IDEs. – Just remember to correctly load the correct

runtime libraries.

cs423-cotter 38