Introduction to the Windows API n API - Application Programming Interface n an API is the software interface for things such as the OS n an API is the.

Slides:



Advertisements
Similar presentations
Sub and Function Procedures
Advertisements

Programming Paradigms and languages
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.
Lecture 1: Overview of Computers & Programming
Tutorial 12: Enhancing Excel with Visual Basic for Applications
The Web Warrior Guide to Web Design Technologies
JavaScript Part for Repetition Statement for statement Cpecifies each of the items needed for counter-controlled repetition with a control variable.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 06.
VBA Modules, Functions, Variables, and Constants
Example 2.
1 Chapter 4 The Fundamentals of VBA, Macros, and Command Bars.
SUNY Morrisville-Norwich Campus-Week 12 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith.
Scope of Variables and Constants A Variable or Constant may exist and be Visible for an entire project, for only one form, or for only one procedure Therefore,
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Chapter 13: Object-Oriented Programming
C++ fundamentals.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Python quick start guide
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Apply Sub Procedures/Methods and User Defined Functions
Chapter Introduction to Computers and Programming 1.
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
Using Data Active Server Pages Objectives In this chapter, you will: Learn about variables and constants Explore application and session variables Learn.
A First Program Using C#
System Calls 1.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
XP New Perspectives on Microsoft Office Access 2003 Tutorial 11 1 Microsoft Office Access 2003 Tutorial 11 – Using and Writing Visual Basic for Applications.
Tutorial 11 Using and Writing Visual Basic for Applications Code
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
1 Web-Enabled Decision Support Systems Objects and Procedures Don McLaughlin IE 423 Design of Decision Support Systems (304)
Why to Create a Procedure
Operator Precedence First the contents of all parentheses are evaluated beginning with the innermost set of parenthesis. Second all multiplications, divisions,
MIPS coding. SPIM Some links can be found such as:
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC BUILDING BLOCKS Bilal Munir Mughal 1 Chapter-5.
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 1 Microsoft Office Excel Copyright © 2008 Pearson Prentice Hall. All rights reserved
Prepared by Fareeha Lecturer DCS IIUI 1 Windows API.
CS 390- Unix Programming Environment CS 390 Unix Programming Environment Topics to be covered: Distributed Computing Fundamentals.
Chapter 2: Operating-System Structures. 2.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 2: Operating-System Structures Operating.
Programming with Microsoft Visual Basic 2008 Fourth Edition
By Noorez Kassam Welcome to JNI. Why use JNI ? 1. You already have significantly large and tricky code written in another language and you would rather.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 7 Sub and Function Procedures.
Lecture Set 11 Creating and Using Classes Part B – Class Features – Constructors, Methods, Fields, Properties, Shared Data.
Linux+ Guide to Linux Certification, Third Edition
CE Operating Systems Lecture 3 Overview of OS functions and structure.
Programming Logic and Design Using Methods. 2 Objectives Review how to use a simple method with local variables and constants Create a method that requires.
IMS 3253: Subroutines 1 Dr. Lawrence West, MIS Dept., University of Central Florida Topics Procedures Subroutines Parameters –By Value.
Covenant College November 27, Laura Broussard, Ph.D. Professor COS 131: Computing for Engineers Chapter 5: Functions.
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC PROGRAMMING FUNDAMENTALS Bilal Munir Mughal 1 Chapter-8.
1 Working with Data Structures Kashef Mughal. 2 Chapter 5  Please review on your own  A few terms .NET Framework - programming model  CLR (Common.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
Introduction to Files in VB Chapter 9.1, 9.3. Overview u Data Files  random access  sequential u Working with sequential files  open, read, write,
Creating Menus Menu Bar – behaves like standard Windows menus Can be used in place of or in addition to buttons to execute a procedure Menu items are controls.
Win32 Programming Lesson 19: Introduction to DLLs.
CHAPTER THREE Representing Data: Constants and Variables.
Tutorial 81 Field, Record, Data File Field - a single item of information about a person, place, or thing Record - a group of related fields that contain.
National Diploma Unit 4 Introduction to Software Development Procedures and Functions.
Programming Logic and Design Fifth Edition, Comprehensive Chapter 7 Using Methods.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Visual Basic Fundamental Concepts
Programming Right from the Start with Visual Basic .NET 1/e
User-Written Functions
An Introduction to Computers and Visual Basic
Using Procedures and Exception Handling
Windows Internals Brown-Bag Seminar Chapter 1 – Concepts and Tools
Visual Basic..
Topics Introduction to File Input and Output
An Introduction to Computers and Visual Basic
Topics Introduction to File Input and Output
Presentation transcript:

Introduction to the Windows API n API - Application Programming Interface n an API is the software interface for things such as the OS n an API is the fundamental level of higher-level programming n in high-level programming, a program has an intermediate to execute tasks n Microsoft Word does not directly control the printing it puts a print task on the OS’s print queue (an API call)

Benefits of API Programming n Using API calls in Visual Basic can cut down on the number of dependency files and thus the size of the application package which you need to deploy to users. n Sometimes now and especially in previous versions of VB API calls were the only way to do certain things like starting and running executable files to do this now use the FSO File System Objects in the Scripting Runtime Library

Benefits of API Programming n Designers of software do not have to worry about the basic chores involved in every program (such as disk access, memory allocation, displaying graphics n Every time there is an improvement in the way hardware is accessed each program would have to be rewritten to take advantage of these changes. n API calls are more powerful than VB methods Powerful meaning can do more / has more features

API Drawbacks n API functions are significantly more error-prone n API functions are prone to fail spectacularly - shut down with a GPF n Visual Basic comes with almost no API documentation n syntactically challenging for non C++ programmers

Where is the Windows API? n C:\Windows\System directory Win32 API another term for these DLLs n user32.dll (user interface functions) most functions we use are in here n kernel32.dll (o.s. kernel functions) n gdi32.dll (graphics device interface functions) n shell32.dll (Windows shell functions).

Accessing the Microsoft Windows API n The Windows API contains thousands of functions, subs, types, and constants that you can declare and use in your projects n These procedures are written in the C language so they must be declared before you can use them with VB n the easiest way to access the Windows API is by using the predefined declares included with Visual Basic

API Viewer Application n API Viewer is a VB Add-In. It uses Win32api.txt, located in the \Winapi subdirectory of the main VB directory. You need to load this file! n The viewer allows you to search through this text file to put together a series of dependant function calls. n Sometimes you need to use functions that get values for the function you’re really interested in using

Components of the Win API n Functions - provide API functionality n Structures multiple individual variables passed between functions n Named Constants - numeric codes for information n Callback Functions defined completely in your program a way to process each item found belonging to the group n Messages are sent to objects to tell them to do something

Declaring the Function n Before an API function can be using in Visual Basic, it must first be declared n The Declare statement can only appear in the (declarations) section of a form or module n If it appears in a form, the declaration must be Private n In a module, the declaration can be either Public or Private

[{Public | Private}] Declare Function function_name Lib "DLL_filename" [Alias "function_alias"] (argument_list) As data_type n function_name - safest to make this the same as the"official" name n DLL_filename - name of the DLL file which stores the function. This does not include the path n function_alias almost every function which has a string as a parameter has two versions ANSI or Unicode for

n English speakers use ANSI ANSI version ends with the letter A Unicode version ends with the letter W n argument_list same as VB n data_type the return type almost always a long [{Public | Private}] Declare Function function_name Lib "DLL_filename" [Alias "function_alias"] (argument_list) As data_type

[{ByVal | ByRef}] argument_name As data_type,... n argument_name - gives clue as to what the argument represents can use any name but best to use “official” name n data type specifies the size and format n Allowed Data types Byte An 8-bit integer. Integer A 16-bit integer. Long A 32-bit integer. String A variable-length string.

ByVal and ByRef n the method used to pass a parameter to the API function n ByVal This method prevents the function from altering the contents n ByRef this method passes a sort of reference to the variable itself n Strings are always passed ByVal structures are always passed ByRef Entire Arrays are always passed ByRef

hDC & hWnd –hWnd Handle A unique 32 bit integer defined by the operating environment and used by a program to identify and switch to an object, such as a form or control. –hDC device context similar in appearance to handles can be the intermediary between your program and a physical device also windows themselves are considered to be devices need hDC to draw (use graphical methods) on an object

Pointers and Flags n pointer a 32-bit integer variable which holds a memory address usually the location of some other object n VB has little support for pointers 99.5% of the time Visual Basic handles pointer for you n A flag is simply a type of named constant. The special thing about flags is that they can be combined with other related flags like (shift control alt) mask

Using API Structures n Structures allow a function to receive or return a large amount of information without cluttering the argument list n Structures almost always group related information n To define a structure in Visual Basic, the Type block is used

[(Public | Private}] Type type_name member1 As data_type1 member2 As data_type2... End Type n type_name The name of the structure n member1, member2,... –The name of an individual member of the structure n data_type1, data_type2,... –The data type of a particular item in the structure

Type EXAMPLESTRUCT longvar As Long another As Long astruct As RECT End TypeRECT n To access a data member of the structure use the. (period) operator between the variable name and the member name n notice one of the members is another structure the RECT angle structure n defined a variable to use the structure Dim ex As EXAMPLESTRUCT ex.longvar = 54 ‘ store 54 here

Rect is a predefined structure If you want to use it you must define it like this Type Rect left As Long top As Long right As Long bottom As Long End Type n Rect a convenient way to keep the necessary coordinates of a rectangle grouped together

Using API Callback Functions n a powerful tool, giving great flexibility to some API functions n allows your program to build its own routines to handle events generated by the API functions themselves n Windows does not define any "default" callback functions n The most common examples of callback functions occur in enumeration

Enumeration n During an enumeration, the invoked API function locates all objects which fit the desired category n However, the API function does not know what to do with all the handles it finds n Callback functions typically process some data with these handles during the middle of a API function call

The AddressOf Operator n The only specific pointer in VB n It is a pointer to an address of a function defined by your program n This function must be Public and be defined in a module (not a form). n can only be used inside of the argument list of a call to a function; it cannot be used any other time