Windows platform API Accumulation

Source: Internet
Author: User
  1. Website
    Http://www.intodigi.com
  2. Openprocesstoken 
    To perform an OpenProcess operation that specifies write-related access to any process (including system security processes and service processes), you only need to grant the current process the sededebug permission. If a user is administrator or has been granted the corresponding permissions, the user can have this permission. However, even if we use the Administrator account to execute OpenProcess (process_all_access, false, dwprocessid) on a system security process, we still encounter an "access denial" error. Why? By default, some access permissions of processes are not set to available (Enabled). Therefore, we must first make these permissions available. Some related API functions include openprocesstoken, lookupprivilegevalue, and adjusttokenprivileges. To modify the access token of a process, first obtain the handle of the Process access token, which can be obtained through openprocesstoken. The prototype of the function is as follows:
    Bool openprocesstoken (
    Handle processhandle, // Process Handle for modifying Access Permissions
    DWORD desiredaccess, // specifies the operation type you want to perform
    Phandle tokenhandle // returned access token pointer
    );
    The return value is not 0;
    Parameter description:
    The first parameter is the process handle for modifying the access permission;
    The third parameter is the returned access token pointer;
    The second parameter specifies the operation type you want to perform. to modify the token, We need to specify the second parameter token_adjust_privileges (for other parameters, see Platform SDK ). Through this function, we can get the access token handle of the current process (specify the first parameter of the function as getcurrentprocess ). Then we can call adjusttokenprivileges to modify the access token.
    Include the header file WINBASE. h
  3. Lookupprivilegevalue
    Obtain the unique identifier (luid) of the specified permission name on the current system. The original function is as follows:
    Bool lookupprivilegevalue (
    Lptstr lpsystemname,
    Lptstr lpname,
    Pluid lpluid
    );
    The return value is not 0;
    Parameter description:
    Lpsystemname
    [In] input parameters, character passing pointer; specify the name of the operating system that requires permission. If null is input, the luid of the specified permission name will be queried on the local system;
    Lpname
    [In] input parameter, string pointer; specify the name of the permission to query luid, which can be defined in the system (such as se_security_name ), it can also be a custom string (such as "sesecurityprivilege ");
    Lpluid
    [Out] outgoing parameter, string pointer; luid specified by outgoing permission name;
    Include the header file WINBASE. h
  4. Adjusttokenprivileges
    Set the process permission to available or unavailable Based on the specified permission token;
    Function prototype:
    Bool adjusttokenprivileges (
    Handle tokenhandle,
    Bool disableallprivileges,
    Ptoken_privileges newstate,
    DWORD bufferlength,
    Ptoken_privileges previusstate,
    Pdword returnlength
    );
    Parameter description:
    Tokenhandle
    [In] the token handle containing the permission to be modified. This parameter must have the token_adjust_privileges permission. If the previusstate parameter is null, the handle should already have the token_query permission.
    Disableallprivileges
    [In] whether all permissions are set to unavailable. if the value is true, all permissions are unavailable and the newstate parameter is ignored. if this parameter is set to false, the function modifies these permissions to the status indicated by the newstate parameter.
    Newstate
    [In] points to an array of token_privileges structures that describe the permission attributes. If disableallprivileges = false, adjusttokenprivileges makes the attributes pointed to in the array available, unavailable, or deleted.
    The three constants se_privilege_enabled, se_privilege_enabled, and se_privilege_removed defined in the system.
    In Windows XP/2000/NT, the permission cannot be deleted
    Bufferlength
    [In] the buffer length indicated by previusstate is specified in bytes. If the previusstate parameter is null, bufferlength can be set to 0.
    Previusstate
    [Out] The adjusttokenprivileges parameter can be transmitted to set the status before modifying the modified attribute. It can be set to null;
    Returnlength
    [Out] the length of the previusstate request in bytes is returned. If previusstate = NULL, this parameter can be null;
    Include the header file WINBASE. h
  5. Openprocesstoken,Lookupprivilegevalue, adjusttokenprivileges reference example
    Bool enabledebugprivilege (bool fenable ){
    Bool Fok = false; // assume function fails
    Handle htoken;
    // Obtain the starting ring of the current process by modifying the options
    If (openprocesstoken (getcurrentprocess (), token_adjust_privileges, & htoken ))
    {
    Token_privileges TP;
    TP. privilegecount = 1;
    // Obtain the luid of the debug permission
    Lookupprivilegevalue (null, se_debug_name, & TP. Privileges [0]. luid );
    // Set the permission attribute to available
    TP. Privileges [0]. Attributes = fenable? Se_privilege_enabled: 0;
    // Modify permissions
    Adjusttokenprivileges (htoken, false, & TP, sizeof (TP), null, null );
    Fok = (getlasterror () = error_success );
    Closehandle (htoken );
    }
    Return (FOK );
    }
  6. Getdlgitem
    Obtain the resource handle in the dialog box.
    Prototype:
    Hwnd getdlgitem (hwnd hdlg, // dialog box handle
    Int niddlgitem // resource ID
    )
    If the call succeeds, the handle of the specified control is returned. If the call fails, null is returned;
  7. Showwindow
    Control window or control display mode (in fact, the control is also a window ).
    Bool showwindow (hwnd, // window handle
    Int ncmdshow // mode, such as sw_hide hiding, sw_maximize maximization, and sw_minimize minimization.
    );
    If the previous window is displayed, non-0 is returned. If the previous window is hidden, 0 is returned;
  8. Getstockfont
    Obtain the font ingredients such as paint brushes and paint brushes of the specified type;
    Hgdiobj getstockobject (
    Int fnobject // font type, such as system_font system font and default_palette default color palette;
    );
    If the call succeeds, the retrieved object is returned. If the call fails, 0 is returned;
  9. Getdc
    Get device context
    HDC getdc (
    Hwnd // window or control handle. If hwnd = NULL, the context of the entire screen is obtained.
    );
    Success: the context of the device in the specified region is returned. If the device fails, null is returned;
  10. Redrawwindow
    Update the specified rectangular area
    Bool redrawwindow (
    Hwnd, // window handle
    Const rect * lprcupdate, // the pointer to the rectangular area to be updated
    Hrgn hrgnupdate, // The region handle to be updated. If lprcupdate and hrgnupdate are empty, the entire customer region will be updated.
    Uint flags // The redraw option. If it is null, the entire region is invalid.
    );
  11. Createconlhelp32snapshot
    Creates a snapshot [snapshot] For the heap [heap], module [module], and thread [thread] used by the specified process and process.
    Handle winapi createconlhelp32snapshot (
    DWORD dwflags,
    DWORD th32processid
    );
    Parameters:
    Dwflags
    [In] specifies the system content contained in the snapshot. This parameter can use one of the following values (variables.
    Th32cs_inherit-the snapshot handle can be inherited.
    Th32cs_snapall-the snapshot contains all processes and threads in the system.
    Th32cs_snapheaplist-the snapshot contains all the heaps of the process specified in th32processid.
    Th32cs_snapmodule-the snapshot contains all the modules of the process specified in th32processid.
    Th32cs_snapprocess-the snapshot contains all processes in the system.
    Th32cs_snapthread-the snapshot contains all the threads in the system.
    Th32processid
    [In] specifies the ID of the process to be snapshot. If this parameter is set to 0, it indicates the current process of the snapshot. This parameter is valid only when th32cs_snapheaplist or th32cs_snapmoudle is set. In other cases, this parameter is ignored and all processes are taken snapshots.
    Return Value:
    If the call is successful, the snapshot handle is returned. If the call fails, the invaid_handle_value is returned.
  12. Process32first
    Obtains information about the first process in the snapshot and sends the process information to lppe.
    Bool winapi process32first (
    Handle hsnapshot, // snapshot returned by createconlhelp32snapshot
    Lpprocessentry32 lppe // [In, out] process snapshot Information Structure
    );
    Returns true if the call is successful, and false if the call fails.
  13. Getdialogbaseunits
    Function: This function returns the basic unit of the system dialogue, which is the average width and height of the system font characters. For the dialog box that uses the system font, you can use these values to convert between the dialog box template, for example, between the dialog box template and pixel. For a dialog box that does not use the system font, the conversion from the unit of the dialog box template to the pixel depends on the font used in the dialog box. The mapdialogrect function is used to easily convert one type of dialog box. mapdialogrect considers the font and correctly converts the unit of a rectangle template to this pixel.
    Function prototype: Long getdialogbaseunits (void );
    Parameter: none.
    Return Value: the return value is a 32-bit value containing the basic unit of the conversation. The low-level characters returned contain the basic unit of the horizontal dialog box, and the high-level characters contain the basic unit of the vertical dialog box.
    Note: The basic horizontal unit returned by the getdialogbaseunits function is the same as the average width of Characters in the system font in pixels. The basic vertical unit is the same as the average height of Characters in the system font in pixels; the basic unit of a dialog box that does not use the system font is equal to the average width and average height of the dialog box font characters in pixels. You can use the gettextmetrics and gettextextentpoint32 functions to calculate these values for a selected font. However, if the calculation result is different from those executed by the system, you can use the mapdialogrect function to avoid possible errors. Each horizontal basic unit is the same as the four horizontal dialog box template units. Each Vertical Basic Unit is the same as the eight vertical dialog box template units. Therefore, use the following formula to convert the template unit of the dialog box to pixels:
    Piselx = (temptateunitx * baseunitx)/4; piseiy = (templateunity * baseunity)/8
    Similarly, the following formula is used to convert pixels into dialog box template units:
    Templateunitx = (pixelx * 4)/baseunitx; templateunity = (plxely * 8)/baseunity
  14. Setwindowpos
    Function: This function changes the size, position, and Z-Order of the pop-up window top-level window. Subwindows, pop-up windows, and top-level windows are sorted according to the order they appear on the screen, and the top-level windows are set to the first window in the Z sequence.
    Function prototype: bool setwindowpos (hwn hwnd, hwnd hwndlnsertafter, int X, int y, int CX, int cy, unit flags );
    Parameters:
    Hwnd: Window handle.
    Hwndlnsertafter: The Window handle located in front of the preset window in Z sequence. This parameter must be a window handle or one of the following values:
    Hwnd_bottom: place the window at the bottom of the Z sequence. If the hwnd parameter identifies a top-level window, the window loses its top-level position and is placed at the bottom of other windows.
    Hwnd_dottopmost: place the window above all non-top-level windows (after all top-level windows ). If the window is already a non-top-level window, the flag does not work.
    Hwnd_top: place the window at the top of the Z sequence.
    Hwnd_topmost: place the window above all non-top-level windows. The top-level position is maintained even if the window is not activated.
    Check g to see how to use this parameter. See the description section.
    X: Specify the left boundary of the new window position with the customer coordinates.
    Y: Specify the top boundary of the new window position with the client coordinates.
    CX: Specify the new width of the window in pixels.
    Cy: Specify the new height of the window in pixels.
    Uflags: indicates the window size and positioning. This parameter can be a combination of the following values:
    Swp_asncwindowpos: If the calling process does not have a window, the system sends a request to the thread that owns the window. This prevents the call thread from deadlocks when other threads process their needs.
    Swp_defererase: prevents wm_syncpaint messages.
    Swp_drawframe: draws a border around the window (defined in the window class description ).
    Swp_framechanged: Send the wm_nccalcsize message to the window, even if the window size does not change. If this flag is not specified, wm_nccalcsize is sent only when the window size is changed.
    Swp_hidewindow; hide the window.
    Swp_noactivate: the window is not activated. If no flag is set, the window is activated and set to the top of another highest level window or a non-highest level group (based on the hwndlnsertafter parameter ).
    Swp_nocopybits: clears all content in the customer zone. If this flag is not set, the valid content of the customer area is saved and copied back to the customer area after the window size is updated and relocated.
    Swp_nomove: Maintain the current position (ignore the X and Y parameters ).
    Swp_noownerzorder: do not change the position of the owner window in Z sequence.
    Swp_noredraw: Do not redraw the changed content. If this flag is set, no re-painting is performed. Applicable to the customer and non-customer areas (including the title bar and scroll bar) and all the parts of the parent window exposed due to window return. If this flag is set, the application must explicitly invalidate the window and redraw any part of the window and the part of the parent window that needs to be repainted.
    Swp_noreposition; the same as the swp_noownerzorder flag.
    Swp_nosendchanging: prevents the window from receiving wm_windowposchanging messages.
    Swp_nosize: Maintain the current size (ignore the Cx and Cy parameters ).
    Swp_nozorder: Maintain the current Z Order (ignore the hwndlnsertafter parameter ).
    Swp_showwindow: display window.
    Return Value: If the function succeeds, the return value is non-zero. If the function fails, the return value is zero. To obtain more error messages, call the getlasterror function.
    NOTE: If swp_showwindow and swp_hidewindow are set, the window cannot be moved or changed. If setwindowloog is used to change some data in the window, you must call the setwindowpos function to make a real change. Use the following combination flag: swp_nomoveiswp_nosizeiswp_framechanged.
    There are two ways to set the window to the top-level window: one is to set the hwndlnsertafter parameter to hwnd_topmost and ensure that the swp_nozorder flag is not set; the other is to set the position of the window in the Z sequence so that it is placed above other existing windows. When a window is set to the top-level window, all its Windows belong to the top-level window, and its owner's Z sequence does not change.
    If the hwnd_topmost and hwnd_notopmost flags are not specified, that is, when the application requires the window to change its position in the Z sequence while activating, the value specified in the hwndinsertafter parameter is only used in the following conditions:
    The hwnd_notopmost and hwnd_topmost flags are not set in the hwndlnsertafter parameter.
    The window identified by the hwnd parameter is not an activation window.
    If you have not set an inactive window to the top of the Z sequence, the application cannot activate the window. The application can change the position of the activated window in the Z sequence without any restriction, or activate a window and move it to the top or the top of the most advanced window.
    If a top-level window is relocated to the bottom of the Z sequence (hwnd_bottom) or after any non-top-level window, the window is no longer the top-level window. When a top-level window is set to a non-top-level window, its owner window and owner window are both non-top-level windows.
    A non-top window can have a top window, but vice versa. Any window that belongs to the top-level window (such as a dialog box) itself is set to the top-level window to ensure that all the owned windows are on top of their owner.
    If the application is not in the foreground, but it should be in the foreground, you should call the setforegroundwindow function to set it.
    When the swp_framechanged flag is specified in the nflags parameter in this function, WindowsCE redraws the entire non-customer area of the window, which may change the size of the customer area. This is also the only way to re-calculate the customer zone, and is usually used after the setwindowlong function is called to change the window style.
  15. View DLL export functions
    If the Platform SDK is installed, you can directly use the depends program to view the DLL functions;
    Operation Method: Enter depends in the command line, run the depends program, and open the menu "file" => "open" to open the DLL for viewing the export function, you can see the export function and related information of the DLL;
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.