⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 w2k_wiz.c

📁 Undocumented Windows 2000 Secrets简体中文版.+源码光盘
💻 C
📖 第 1 页 / 共 2 页
字号:

// __________________________________________________________
//
//                         w2k_wiz.c
//             SBS Windows 2000 Code Wizard V1.00
//                08-27-2000 Sven B. Schreiber
//                       sbs@orgon.com
// __________________________________________________________

#include "w2k_wiz.h"

// =================================================================
// DISCLAIMER
// =================================================================

/*

This software is provided "as is" and any express or implied
warranties, including, but not limited to, the implied warranties of
merchantability and fitness for a particular purpose are disclaimed.
In no event shall the author Sven B. Schreiber be liable for any
direct, indirect, incidental, special, exemplary, or consequential
damages (including, but not limited to, procurement of substitute
goods or services; loss of use, data, or profits; or business
interruption) however caused and on any theory of liability,
whether in contract, strict liability, or tort (including negligence
or otherwise) arising in any way out of the use of this software,
even if advised of the possibility of such damage.

*/

// =================================================================
// REVISION HISTORY
// =================================================================

/*

08-27-2000 V1.00 Original version (SBS).

*/

// =================================================================
// MESSAGE TEXTS
// =================================================================

TBYTE gatAborted [] = T("\r\nInitialization error\r\n");
TBYTE gatTarget  [] = T("\r\nProject %s\r\n");
TBYTE gatLoading [] = T("\r\nLoading %s ... ");
TBYTE gatWriting [] = T(    "Writing %s ... ");
TBYTE gatOk      [] = T("OK");
TBYTE gatError   [] = T("ERROR");
TBYTE gatLine    [] = T("%s\r\n");

// =================================================================
// GLOBAL VARIABLES
// =================================================================

BYTE gabName     [MAX_PATH];  // %n = project name (canonical)
BYTE gabNameU    [MAX_PATH];  // %N = project name (upper case)
BYTE gabSettings [MAX_PATH];  // %s = settings path

BYTE gabDay      [N_DECIMAL]; // %d = current day
BYTE gabMonth    [N_DECIMAL]; // %m = current month
BYTE gabYear     [N_DECIMAL]; // %y = current year

BYTE gabText     [N_VALUE];   // %t = default description
BYTE gabCompany  [N_VALUE];   // %c = author's company
BYTE gabAuthor   [N_VALUE];   // %a = author's name
BYTE gabEmail    [N_VALUE];   // %e = author's email address
BYTE gabPrefix   [N_VALUE];   // %p = author's ProgID prefix

BYTE gabInclude  [N_VALUE];   // %i = DDK include path
BYTE gabFree     [N_VALUE];   // %l = DDK library path (release)
BYTE gabChecked  [N_VALUE];   // %L = DDK library path (debug)

// =================================================================
// REGISTRY MANAGEMENT
// =================================================================

BOOL WINAPI RegistryRoot (PTBYTE ptRoot,
                          PHKEY  phk)
    {
    BOOL fOk = FALSE;

    if (phk != NULL)
        {
        if      (!lstrcmpi (ptRoot, T("HKEY_CLASSES_ROOT")))
            {
            *phk = HKEY_CLASSES_ROOT;
            }
        else if (!lstrcmpi (ptRoot, T("HKEY_CURRENT_USER")))
            {
            *phk = HKEY_CURRENT_USER;
            }
        else if (!lstrcmpi (ptRoot, T("HKEY_LOCAL_MACHINE")))
            {
            *phk = HKEY_LOCAL_MACHINE;
            }
        else if (!lstrcmpi (ptRoot, T("HKEY_USERS")))
            {
            *phk = HKEY_USERS;
            }
        else if (!lstrcmpi (ptRoot, T("HKEY_PERFORMANCE_DATA")))
            {
            *phk = HKEY_PERFORMANCE_DATA;
            }
        else if (!lstrcmpi (ptRoot, T("HKEY_CURRENT_CONFIG")))
            {
            *phk = HKEY_CURRENT_CONFIG;
            }
        else if (!lstrcmpi (ptRoot, T("HKEY_DYN_DATA")))
            {
            *phk = HKEY_DYN_DATA;
            }
        else
            {
            *phk = INVALID_HKEY;
            }
        fOk = (*phk != INVALID_HKEY);
        }
    return fOk;
    }

// -----------------------------------------------------------------

BOOL WINAPI RegistryParse (PTBYTE  ptPath,
                           PHKEY   phkRoot,
                           PPTBYTE pptKey,
                           PPTBYTE pptValue)
    {
    DWORD dStop;
    HKEY  hkRoot = INVALID_HKEY;
    DWORD dKey   = 0;
    DWORD dValue = 0;

    if (ptPath != NULL)
        {
        while (ptPath [dKey] && (ptPath [dKey] != '\\'))
              dKey++;

        if (ptPath [dKey]) ptPath [dKey++] = 0;

        dValue = dStop = dKey + lstrlen (ptPath + dKey);

        while ((dValue > dKey) && (ptPath [dValue-1] != '\\'))
              dValue--;

        if (dValue > dKey) ptPath [dValue-1] = 0; else dKey = dStop;

        RegistryRoot (ptPath, &hkRoot);
        }
    if (phkRoot  != NULL) *phkRoot  = hkRoot;
    if (pptKey   != NULL) *pptKey   = ptPath + dKey;
    if (pptValue != NULL) *pptValue = ptPath + dValue;
    return (hkRoot != INVALID_HKEY);
    }

// -----------------------------------------------------------------

DWORD WINAPI RegistryRead (PTBYTE ptPath,
                           PTBYTE ptBuffer,
                           DWORD  dBuffer)
    {
    HKEY   hkRoot, hk;
    PTBYTE ptKey, ptValue;
    DWORD  dType;
    DWORD  n = 0;

    if ((ptBuffer != NULL) && dBuffer)
        {
        if (RegistryParse (ptPath, &hkRoot, &ptKey, &ptValue)
            &&
            (RegOpenKeyEx (hkRoot, ptKey, 0, KEY_READ, &hk)
             == ERROR_SUCCESS))
            {
            n = dBuffer * sizeof (TBYTE);

            if ((RegQueryValueEx (hk, ptValue, NULL,
                                  &dType, (PVOID) ptBuffer, &n)
                 == ERROR_SUCCESS)
                &&
                (dType == REG_SZ))
                {
                if (n /= sizeof (TBYTE)) n--;
                }
            else
                {
                n = 0;
                }
            RegCloseKey (hk);
            }
        ptBuffer [n] = 0;
        }
    return n;
    }

// =================================================================
// FILE MANAGEMENT
// =================================================================

DWORD WINAPI FileRoot (PTBYTE ptPath)
    {
    DWORD dRoot = 0;

    if ((ptPath != NULL) && ptPath [0])
        {
        if (ptPath [0] == '\\')
            {
            if (ptPath [1] == '\\')
                {
                for (dRoot = 2;
                     ptPath [dRoot] && (ptPath [dRoot] != '\\');
                     dRoot++);
                }
            }
        else
            {
            if (ptPath [1] == ':') dRoot = 2;
            }
        }
    return dRoot;
    }

// -----------------------------------------------------------------

HANDLE WINAPI FileOpen (PTBYTE ptPath)
    {
    HANDLE hf = INVALID_HANDLE_VALUE;

    if ((ptPath != NULL) && ptPath [0])
        {
        hf = CreateFile (ptPath, GENERIC_READ,
                         FILE_SHARE_READ, NULL, OPEN_EXISTING,
                         FILE_FLAG_SEQUENTIAL_SCAN, NULL);
        }
    return hf;
    }

// -----------------------------------------------------------------

HANDLE WINAPI FileNew (PTBYTE ptPath)
    {
    DWORD  i;
    HANDLE hf = INVALID_HANDLE_VALUE;

    if ((ptPath != NULL) && ptPath [0])
        {
        i = FileRoot (ptPath);

        while (ptPath [i])
            {
            while (ptPath [i] && (ptPath [++i] != '\\'));

            if (ptPath [i] == '\\')
                {
                ptPath [i] = 0;
                CreateDirectory (ptPath, NULL);
                ptPath [i] = '\\';
                }
            }
        hf = CreateFile (ptPath, GENERIC_READ | GENERIC_WRITE,
                         FILE_SHARE_READ, NULL, CREATE_ALWAYS,
                         FILE_FLAG_SEQUENTIAL_SCAN |
                         FILE_ATTRIBUTE_NORMAL, NULL);
        }
    return hf;
    }

// -----------------------------------------------------------------

HANDLE WINAPI FileClose (HANDLE hf)
    {
    if (hf != INVALID_HANDLE_VALUE) CloseHandle (hf);
    return INVALID_HANDLE_VALUE;
    }

// -----------------------------------------------------------------

PBYTE WINAPI FileUnload (PBYTE pbData)
    {
    if (pbData != NULL) LocalFree (pbData);
    return NULL;
    }

// -----------------------------------------------------------------

PBYTE WINAPI FileLoad (PTBYTE ptPath,
                       PDWORD pdData)
    {
    HANDLE hf;
    DWORD  n;
    DWORD  dData  = 0;
    PBYTE  pbData = NULL;

    if ((hf = FileOpen (ptPath)) != INVALID_HANDLE_VALUE)
        {
        dData = GetFileSize (hf, NULL);

        if ((dData != INVALID_FILE_SIZE) && (dData < MAXDWORD) &&
            ((pbData = LocalAlloc (LMEM_FIXED, dData+1)) != NULL))
            {
            if (ReadFile (hf, pbData, dData, &n, NULL) &&
                (dData == n))
                {
                pbData [dData] = 0;
                }
            else
                {
                pbData = FileUnload (pbData);
                }
            }
        FileClose (hf);

        if (pbData == NULL) dData = 0;
        }
    if (pdData != NULL) *pdData = dData;
    return pbData;
    }

// -----------------------------------------------------------------

BOOL WINAPI FileWrite (HANDLE hf,
                       PBYTE  pbData,
                       DWORD  dData)
    {
    DWORD dData1, n;
    BOOL  fOk = FALSE;

    if ((hf != INVALID_HANDLE_VALUE) && (pbData != NULL))
        {
        dData1 = (dData != MAXDWORD ? dData : lstrlenA (pbData));

        fOk = WriteFile (hf, pbData, dData1, &n, NULL) &&
              (dData1 == n);
        }
    return fOk;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -