390 likes | 521 Vues
This guide provides an overview of the Windows operating environment, specifically targeting the 32-bit architecture of Windows XP. It details the use of Microsoft Visual Studio .NET for programming, covering project creation, file management, and library integration. Instructions for retrieving IP addresses, using command prompts, and configuring multi-threaded applications are explored. The guide also lists essential tools available on SCE machines including web browsers, business applications, and programming aids. This resource is ideal for students and developers working in Windows environments.
E N D
Windows Operating Environment • 32 bit operating environment – Windows XP • Microsoft Visual Studio.net, .net2005, 6.0 • STB Rooms 460, 462, 464 • 75 machines – P4 class • Personal storage on remote machines • Q: drive (60 MB), Y: drive (100MB) • Most programs on local hosts
Windows Operating Environment • Tools Available on SCE machines: • Web Browsers (Netscape, Explorer) • Business tools (MS Office) • Math tools (Maple, Matlab) • Programming tools ( MSVC++6.0, etc. ) • ftp • telnet • etc.
Find IP Address of XP 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
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:\>
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 • Identify storage location for new project • Provide Project name • OK
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.
Windows ProgrammingAdd Libraries • Project -- Properties • linker tab -- category = Input -- add library names to “Additional Dependencies” • for sockets, add “wsock32.lib”
To support Multi-threaded Programs: • Select Project Program Properties • Select C/C++ tab • Code Generation subtab • Runtime Library item: • Default is “Single-threaded Debug (/MLd)” • Select “Multi-threaded Debug DLL (/MDd)”
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.
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”
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.
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
_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
consum.cpp - multithreading #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; }
consum.cpp - multithreading 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); }
consum.cpp - Results The value of i is 0 The value of i is 1 The value of i is 2 The value of i is 3 The value of i is 4 The value of i is 5 The sum is 15
consum2.cpp - multithreading #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; }
consum2.cpp - multithreading 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); }
consum.cpp - Results The value of i is 0 The value of i is 1 The value of i is 2 The value of i is 3 The value of i is 4 The sum is 10 The value of i is 0 The value of i is 1 The value of i is 2 The value of i is 3 The value of i is 4 The value of i is 5 The sum is 15
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; } 35 cs423-cotter
consumfloat.cpp void 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
Consumfloat.cpp Results The number is 9 The factorial product is 362880 The float is 9.00 The number is 12 The factorial product is 479001600 The float is 12.00 Press any key to continue . . .
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.