Win32 Programming Lesson 5: Error Codes. Before We Begin  Much of the time in this class we’ll be calling Win32 Functions  However, sometimes they’re.

Slides:



Advertisements
Similar presentations
MPI 2.2 William Gropp. 2 Scope of MPI 2.2 Small changes to the standard. A small change is defined as one that does not break existing correct MPI 2.0.
Advertisements

Detecting Bugs Using Assertions Ben Scribner. Defining the Problem  Bugs exist  Unexpected errors happen Hardware failures Loss of data Data may exist.
C Structures and Memory Allocation There is no class in C, but we may still want non- homogenous structures –So, we use the struct construct struct for.
Things to Remember When Developing 64-bit Software OOO "Program Verification Systems"
Introduction to Linked Lists In your previous programming course, you saw how data is organized and processed sequentially using an array. You probably.
Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
This Time Pointers (declaration and operations) Passing Pointers to Functions Const Pointers Bubble Sort Using Pass-by-Reference Pointer Arithmetic Arrays.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Chapter 10.
Nov 10, Fall 2006IAT 8001 Debugging. Nov 10, Fall 2006IAT 8002 How do I know my program is broken?  Compiler Errors –easy to fix!  Runtime Exceptions.
11-Jun-15 Exceptions. 2 Errors and Exceptions An error is a bug in your program dividing by zero going outside the bounds of an array trying to use a.
16-Jun-15 Exceptions. Errors and Exceptions An error is a bug in your program dividing by zero going outside the bounds of an array trying to use a null.
Exceptions. Errors and Exceptions An error is a bug in your program –dividing by zero –going outside the bounds of an array –trying to use a null reference.
Software and Software Vulnerabilities. Synopsis Array overflows Stack overflows String problems Pointer clobbering. Dynamic memory management Integer.
Guide To UNIX Using Linux Third Edition
. Memory Management. Memory Organization u During run time, variables can be stored in one of three “pools”  Stack  Static heap  Dynamic heap.
CSE 332: C++ program structure and development environment C++ Program Structure (and tools) Today we’ll talk generally about C++ development (plus a few.
June 14, 2001Exception Handling in Java1 Richard S. Huntrods June 14, 2001 University of Calgary.
COMPUTER PROGRAMMING 2 Exceptions. What are Exceptions? Unexpected events that happen when the code is executing (during runtime). Exceptions are types.
Win32 Programming Lesson 13: Thread Pooling (Wow, Java is good for something…)
Files COP3275 – PROGRAMMING USING C DIEGO J. RIVERA-GUTIERREZ.
Win32 Programming Lesson 16: Virtual Memory. Where are we?  We’ve covered the theory of Windows memory, and poked around some  Now let’s use how to.
Win32 Programming Lesson 20: Advanced DLL Techniques.
Chapter 0.2 – Pointers and Memory. Type Specifiers  const  may be initialised but not used in any subsequent assignment  common and useful  volatile.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
Win32 Programming Lesson 7: Kernel Objects. Abstract  Many of the concepts we’ll look at today won’t make complete sense until you use them  However,
Copyright  Hannu Laine C++-programming Part 1 Hannu Laine.
Character Arrays Based on the original work by Dr. Roger deBry Version 1.0.
Java 5 Part 1 CSE301 University of Sunderland Harry Erwin, PhD.
CS Midterm Study Guide Fall General topics Definitions and rules Technical names of things Syntax of C++ constructs Meaning of C++ constructs.
File IO and command line input CSE 2451 Rong Shi.
Chapter 13 – C++ String Class. String objects u Do not need to specify size of string object –C++ keeps track of size of text –C++ expands memory region.
Writing a Run Time DLL The application loads the DLL using LoadLibrary() or LoadLibraryEx(). The standard search sequence is used by the operating system.
C Functions Three major differences between C and Java functions: –Functions are stand-alone entities, not part of objects they can be defined in a file.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Stacks.
Chapter 4 Introduction to Classes, Objects, Methods and strings
Lecture 6 C++ Programming Arne Kutzner Hanyang University / Seoul Korea.
Module 4: I/O and Strings #1 2000/01Scientific Computing in OOCourse code 3C59 Module 4: I/O In this module we will cover Keyboard/screen input and output.
How to write a MSGQ Transport (MQT) Overview Nov 29, 2005 Todd Mullanix.
Queues Chapter 5 Queue Definition A queue is an ordered collection of data items such that: –Items can be removed only at one end (the front of the queue)
COP 3275 – Character Strings Instructor: Diego Rivera-Gutierrez.
Chapter 8 Characters and Strings. Objectives In this chapter, you will learn: –To be able to use the functions of the character handling library ( ctype).
FILES. open() The open() function takes a filename and path as input and returns a file object. file object = open(file_name [, access_mode][, buffering])
1 CSC103: Introduction to Computer and Programming Lecture No 28.
Exception Handling in C + + Introduction Overview of C++ Exception Handling Designing With Exceptions Exception Handling Philosophies Conclusion.
Programming Fundamentals. Today’s Lecture Array Fundamentals Arrays as Class Member Data Arrays of Objects C-Strings The Standard C++ string Class.
Files A collection of related data treated as a unit. Two types Text
Lecture 20: C File Processing. Why Using Files? Storage of data in variables and arrays is temporary Data lost when a program terminates. Files are used.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
C Programming Day 2. 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/LA07/003 Version No. 1.0 Union –mechanism to create user defined data types.
Announcements Remember what we talked on Tuesday in terms of Makefiles and phony targets. Don’t lose points for this! BTW, the.PHONY target can appear.
C++ Functions A bit of review (things we’ve covered so far)
Chapter 02. Starting Windows Socket. IT COOKBOOK  Goal Error handling routine for Winsock function error Winsock startup and cleanup Socket creation.
Objects and Memory Mehdi Einali Advanced Programming in Java 1.
Eighth Lecture Exception Handling in Java
Memory Management.
Value-Returning Functions
Testing and Debugging.
Section 64 – Manipulating Data Using Methods – Java Swing
Computer Programming I
Format String.
when need to keep permanently
Windows APIs Some odds and ends Copyright © 1997 – 2016 Curt Hill.
Java Programming Language
Exceptions 25-Apr-19.
Exceptions 22-Apr-19.
Exceptions 10-May-19.
Exceptions 5-Jul-19.
Memory allocation.
Presentation transcript:

Win32 Programming Lesson 5: Error Codes

Before We Begin  Much of the time in this class we’ll be calling Win32 Functions  However, sometimes they’re not going to work as you expect  How do you deal with the unexpected?

First, a question  What’s the difference between these lines, and how is that difference realized: void main() { node *foo; foo = new node(); node bar; … }

Return Codes  Windows functions (and C/C++ calls in general) can only directly return one value… why?

Common Win32 Returns  VOID: This function cannot possibly fail (Ha!)  BOOL: Success is 0. Non-zero is a failure. Check for 0 or not 0… don’t check for TRUE  HANDLE: NULL (failure) or an OBJECT which can be manipulated  PVOID: NULL (failure) or a Pointer to an area of memory  LONG/DWORD: 0 or -1 for failure – sometimes. Varies from function to function

Tracking Errors  The actual error code is stored in thread local storage Remember that term, we’ll be looking at it a lot later For now, that means every thread has its own error codes  MSDN: DWORD GetLastErrorGetLastError

The Actual Values  Stored in WinError.h // // MessageId: ERROR_INVALID_FUNCTION // // MessageText: // // Incorrect function. // #define ERROR_INVALID_FUNCTION 1L // dderror // // MessageId: ERROR_FILE_NOT_FOUND // // MessageText: // // The system cannot find the file specified. // #define ERROR_FILE_NOT_FOUND 2L

Not Very Helpful…  People don’t do well with numbers  Need to convert into a Text String  Fortunately, there is a way!

FormatMessage  DWORD FormatMessage( DWORD dwFlags, LPCVOID pSource, DWORD dwMessageId, DWORD dwLanguageId, PTSTR pszBuffer, DWORD nSize, va_list *Arguments);FormatMessage

MSDN  It’s an invaluable resource but you have to learn how to use it  I’ll do this one for you… some of the rest you will have to do on your own

Parm by Parm  dwFlags: (in) Something we supply. FORMAT_MESSAGE_FROM_SYSTEM gives us the result from GetLastError  lpSource: (in) Where the definitions are – for us, NULL.  dwMessageId: (in) The message we want to translate

Parm by Parm (ctd)  dwLanguageID: (in) What language to format the message in  lpBuffer: (out) The buffer for the message Can be auto-alloced  nSize: (in) Either: the size of the output, or the minimum number of TCHARS the message will contain  Arguments: (in) Pointer to an array of values to insert into the formatted message

FormatString in Action  BOOL fOk = FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | FORM AT_MESSAGE_ALLOCATE_BUFFER, NULL, dwError, MAKELANGID(LANG_ENGLISH, SUBLANG_E NGLISH_US), (LPTSTR) &hlocal, 0, //dwSize NULL);

A GUI Version  Turns out to be very tricky, due to one parameter which is hard to marshal: va_list  Why is this hard? .NET implements its own object to get around this: Win32ExceptionWin32Exception Note here how we’re getting into some of the “gnarliness” of Win32