• Windows API 第三篇


    1.获得程序自身的路径:

    DWORD GetModuleFileName(
      HMODULE hModule,    // handle to module
      LPTSTR lpFilename,  // path buffer
      DWORD nSize         // size of buffer
    );
    参数说明:
    hModudle :[in] Handle to the module whose path is being requested. If this parameter is NULL, GetModuleFileName retrieves the path for the current module.
    lpFilename: [out] Pointer to a buffer that receives the fully-qualified path for the module. If the length of the string exceeds the size specified by the nSize parameter, the string is truncated.
    nSize:[in] Specifies the length of the lpFilename buffer, in TCHARs.

    返回值:

    If the function succeeds, the return value is the length of the string copied to the buffer, in TCHARs.

    If the function fails, the return value is zero. To get extended error information, call GetLastError.

    2. 获取windows目录

    UINT GetWindowsDirectory(
      LPTSTR lpBuffer,  // buffer for Windows directory
      UINT uSize        // size of directory buffer
    );
    参数说明:
    lpBuffer: [out] Pointer to the buffer to receive the null-terminated string containing the path. This path does not end with a backslash unless the Windows directory is the root directory. For example, if the Windows directory is named Windows on drive C, the path of the Windows directory retrieved by this function is C:Windows. If the system was installed in the root directory of drive C, the path retrieved is C:
     uSize:  [in] Specifies the maximum size, in TCHARs, of the buffer specified by the lpBuffer parameter. This value should be set to MAX_PATH+1 to allow sufficient space for the path and the null terminator. 

    返回值:
    f the function succeeds, the return value is the length, in TCHARs, of the string copied to the buffer, not including the terminating null character. If the length is greater than the size of the buffer, the return value is the size of the buffer required to hold the path.If the function fails, the return value is zero. To get extended error information, call GetLastError.

    3. 获取系统目录
    UINT GetSystemDirectory( LPTSTR lpBuffer, // buffer for system directory UINT uSize // size of directory buffer );
    参数说明:
    lpBuffer
    [out] Pointer to the buffer to receive the null-terminated string containing the path. This path does not end with a backslash unless the system directory is the root directory. For example, if the system directory is named WindowsSystem on drive C, the path of the system directory retrieved by this function is C:WindowsSystem.
    uSize:[in] Specifies the maximum size of the buffer, in TCHARs. This value should be set to at least MAX_PATH+1 to allow sufficient space for the path and the null terminator.

    返回值判断:

    If the function succeeds, the return value is the length, in TCHARs, of the string copied to the buffer, not including the terminating null character. If the length is greater than the size of the buffer, the return value is the size of the buffer required to hold the path.

    If the function fails, the return value is zero. To get extended error information, call GetLastError.

  • 相关阅读:
    .NET Core log4net 使用(转贴)
    Tomcat的工作原理
    Servlet工作原理
    java实现快速排序
    正则表达式积累
    js常用知识真理
    最常用的的设计模式
    【设计模式】单例设计模式
    java中堆栈区别,递归和迭代区别
    Struts2的工作原理
  • 原文地址:https://www.cnblogs.com/priarieNew/p/9753937.html
Copyright © 2020-2023  润新知