Академический Документы
Профессиональный Документы
Культура Документы
What is DLL?
A dynamic-link library (DLL) is an executable file that acts as a shared library of functions. Dynamic linking provides a way for a
process to call a function that is not part of its executable code. The executable code for the function is located in a DLL, which
contains one or more functions that are compiled, linked, and stored separately from the processes that use them. DLLs also facilitate
the sharing of data and resources. Multiple applications can simultaneously access the contents of a single copy of a DLL in memory.
Saves disk space. Many applications can share a single copy of the DLL on disk. In contrast, each application built with a static link
library has the library code linked into its executable image as a separate copy.
Upgrades to the DLL are easier. When the functions in a DLL change, the applications that use them do not need to be recompiled or
relinked as long as the function arguments and return values do not change. In contrast, statically linked object code requires that the
application be relinked when the functions change.
Provides after-market support. For example, a display driver DLL can be modified to support a display that was not available when the
application was shipped.
Supports multi language programs. Programs written in different programming languages can call the same DLL function as long as the
programs follow the function's calling convention. The programs and the DLL function must be compatible in the following ways: the
order in which the function expects its arguments to be pushed onto the stack, whether the function or the application is responsible for
cleaning up the stack, and whether any arguments are passed in registers.
include <windows.h>
#include <stdio.h>
// Import function that adds two numbers
extern "C" __declspec(dllimport) double AddNumbers(double a, double b);
int main(int argc, char *argv[])
{
double result = AddNumbers(1, 2);
printf("The result was: %f\n", result);
return 0;
}
c
We want to store a character String (³XYZ´ )in the dynamic memory:
1.Define a handle to the memory block
HANDLE hMem;
if (hMem == NULL)
MessageBox(hwnd,´No more room in local memory´,´warning´, MB_OK);
hMem
ï
3.Define a near pointer to a character String
PSTR pstr;
HANDLE hMem;
hMem = LocalAlloc( LMEM_MOVABLE | LMEM_ZEROINIT,5);
//Now increase the memory size
hMem = LocalReAlloc(hMem, 256, ( LMEM_MOVABLE );
!
"#
PSTR pstr;
lstrcpy(pstr,´XYZ´);
LocalUnlock(hMem);
}
c $
%!
Clipboard is just a memory block that windows maintain. Application can pass the data to the clipboard. Because the clipboard is
maintained by the windows environment, its contents are available to any running program.
The data types are exchanged through the clipboard are text(CF_TEXT) and bitmaps (CF_BITMAP, CF_TIFF, CF_PALETTE)
%! #
1.OPENCLIPBOARD:
Purpose: It opens the clipboard for reading and writing of its contents. The clipboard must be open before read its content or write the
content to it. The clipboard must be opened and closed during the processing of a single window message.
Syntax: BOOL OpenClipboard (HWND hwnd)
Parameters: hwnd --- The handle of the window that is opening the clipboard.
Header Needed: winuser.h
2.SETCLIPBOARDDATA:
Purpose: It places the data in the clipboard for a given clipboard format. This is the only way to set the contents of the clipboard. Before
places the data in the clipboard , the clipboard must be opened.
Syntax: HANDLE SetClipboardData (uINT wFormat, HANDLE hMem)
Parameters:
wFormat : Specifies the type of the data.
hMem: A handle to the global memory block that contains the data in specified format.
Header Needed: winuser.h
3.GETCLIPBOARDDATA:
Purpose: It retrieves the data from the clipboard .
Syntax: HANDLE GetClipboardData(UINT wFormat)
Parameters: wFormat: Specifies the clipboard format for the data.
Header Needed: winuser.h
4.EMPTYCLIPBOARD:
Purpose: It deletes the contents of clipboard and frees the associated data.
Syntax: BOOL EmptyClipboard(void)
Header Needed: winuser.h
5.CLOSECLIPBOARD:
Purpose: It closes the clipboard for reading and writing the data.
Syntax: BOOL CloseClipboard(void)
c &!
%
What is bitmap?
Bitmaps are blocks of data that can be output directly to the device. They can be thought of as a way to store the pixel data directly
from the screen into a memory buffer. Painting bitmap onto the screen is much faster than using the GDI functions like Rectangle ()etc.
The drawbacks to the bitmaps are that they take a lot of memory and disk space and they can not scale well, especially if they contain
the text.
LoadBitmap(): It loads the bitmap resource from the module µ s resource file.This function can load the device dependent bitmap or
device independent bitmap.
Syntax: HBITMAP loadBitmap( HINSTANCE hInstance, LPCSTR lpszBitmap)
!
Message Box: AY Y is a special kind of modal dialog box that an application uses to display messages and prompt for input.
A message box typically contains a text message and one or more predefined buttons. The following screen shot shows a message box.
The MessageBox function creates, displays, and operates a message box. The message box contains an application-defined message
and title, plus any combination of predefined icons and push buttons.
int MessageBox(
HWNDY
, // handle to owner window
LPCTSTRY
, // text in message box
LPCTSTRY
, // message box title
UINTY
// message box style
);
eg:
MessageBox (hWnd, "bfileStatus is positive", "Warning", MB_OK);
Modeless Dialog box
! allows the user to switch between the dialog box and the parent window.
This type of the dialog box is preferred when the user would find it convenient to keep the displayed for a while.
(For instance the word processor often use modeless dialog box for the text finding)
In the modeless dialog box, the message comes through the program¶s message queue. The message queue must be altered to pass these
messages to the dialog box window procedure.
Use the DestroyWindow rather than EndDialog to end a modeless dialog box.
c '
File Creation:
CreateFile : The CreateFile function creates or opens the following objects and returns a handle that can be used to access the object:
HANDLE CreateFile(
LPCTSTRY
, // file name
DWORDY, // access mode
DWORD , // share mode
LPSECURITY_ATTRIBUTESY
, // Security information
DWORDY
, // how to create
DWORDY
, // file attributes
HANDLEY
// handle to template file
);
Access Mode:
GENERIC_READ Specify the read access. Data can be read from the file and the file pointer can be
moved.
GENERIC_WRITE Specify the write access. Data can be write to the file and the file pointer can be
moved.
Share Mode:
FILE_SHARE_READ Group and other user has the read permission.
FILE_SHARE_WRITE Group and other user has the write permission.
How to create:
CREATE_NEW Create a new file. The function fails if the file already exists.
CREATE_ALWAYS Create a new file. The function over writes if the file already exists.
OPEN_ALWAYS Opens the file if it exists. Other wise it creates the file.
File Attribute:
FILE_ATTRIBUTE_NORMAL The file is normal.
FILE_ATTRIBUTE_HIDDEN If the file is hidden file.
FILE_ATTRIBUTE_SYSTEM If the file is system file.
FILE_ATTRIBUTE_ARCHIVE If the file is back up file.
File creation:
HANDLE hFile;
HFile= CreateFile(³File1.txt´, // File name
GENERIC_READ | GENERIC_WRITE, // specify the access mode
FILE_SHARE_READ, // shared mode
NULL, // Security Information
OPEN_ALWAYS, // how to create
FILE_ATTRIBUTE_NORMAL, // File attribute
NULL);
Example:
int hFileHandle;
char data [ ] = ³How to write to the file´;
hFileHandle = _lopen (³File1.txt´, OF_WRITE); // open the file
Example:
int hFileHandle;
char data [ 128];
hFileHandle = _lopen (³File1.txt´, OF_READ);
Origin: If the file pointer is at the beginning of the file then it will be 0.
If the file pointer is at the end of the file then it will be 2.
For the current location, it will be 1.
Example:
) #
int hFileHandle;
// Go to end of file
_llseek(hFileHandle, 0L, 2);
// Go to beginning of file
_llseek(hFileHandle, 0L, 0);
*
int hFileHandle;
int hFileHandle;
char data [ 128];
hFileHandle = _lopen (³File1.txt´, OF_READ);
// Go to end of file
int filesize = (int)_llseek(hFileHandle, 0L, 2);
// Move to the beginning of the file
_llseek(hFileHandle, 0L, 0);
%%
int hFileHandle;
char data [ 128] = ³Hello Win 32 File operation´;
hFileHandle = _lopen (³File1.txt´, OF_WRITE);
// Go to end of file
int filesize = (int)_llseek(hFileHandle, 0L, 2);
TextOut: The function writes the character string at the specified location, using the currently selected font.
Syntax: BOOL textOut ( HDC hdc, int x, int y, LPSTR lpszstr, int stringlength)
DrawText: This function is used to draw the specified text. It supports the text formatting also.
Syntax: int DrawText ( HDC hdc, LPSTR string, int length, LPRECT rect, UINT flags)
SetTextColor: It sets the text color for the device context to a specified color. The default text color for the device context is black. The
function allows any RGB color for the text output. The color stays in effect until the device context is released or another color is set.
Syntax: COLOREF SetTextColor (HDC hdc, COLORREF newcolor)
SetTextAlign: It sets the text alignment flags for the device context. This function allows an application to change the alignment
location to other location on the first character.
GETDC: GetDC () retrieves the handle of the display device context for the client area of the window. You can use the display DC in
subsequent GDI functions to draw in the client area.
Syntax: HDC GetDC( HWND hwnd)
ReleaseDC: It releases the device context, making it available for use by the other application. It releases the common and windows
DC.
Syntax: int ReleaseDC(HWND hWnd, HDC hdc)