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

📄 devload.c

📁 windows ce 3.00 嵌入式操作系统源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
    )
{
    BOOL bRet;
    HKEY DevKey;
    HKEY MultiKey;
    DWORD status;
    DWORD RegEnum;
    DWORD ValLen;
    DWORD ValLen1;
    LPTSTR  RegPathPtr;
    
    DEBUGMSG(ZONE_ACTIVE,
        (TEXT("DEVICE!StartDriver starting HLM\\%s.\r\n"), RegPath));

    status = RegOpenKeyEx(
                HKEY_LOCAL_MACHINE,
                RegPath,
                0,
                0,
                &DevKey);
    if (status) {
        DEBUGMSG(ZONE_ACTIVE|ZONE_ERROR,
            (TEXT("DEVICE!StartDriver RegOpenKeyEx(%s) returned %d.\r\n"),
            RegPath, status));
        return FALSE;
    }

    //
    // If the "MULTI" key exists below this driver, then load the list of
    // drivers under this key.
    //
    status = RegOpenKeyEx(
                DevKey,
                TEXT("MULTI"),
                0,
                0,
                &MultiKey);
    RegCloseKey(DevKey);
    if (status) {
        //
        // No "MULTI" key, just load the driver like we used to.
        //
        DEBUGMSG(ZONE_ACTIVE|ZONE_ERROR,
            (TEXT("DEVICE!StartDriver Loading %s (key x%X, status %d).\r\n"), RegPath, DevKey, status));
        return StartOneDriver(RegPath, PnpId, LoadOrder, 0, hSock) == NULL ?
                    FALSE : TRUE;
    }

    //
    // Add "\\MULTI\\" to the registry path
    //
    DEBUGMSG(ZONE_ACTIVE|ZONE_ERROR,
             (TEXT("DEVICE!StartDriver RegPath %s\r\n"),
              RegPath));
    RegPathPtr = RegPath + _tcslen(RegPath);
    _tcscat(RegPath, TEXT("\\MULTI\\"));
    RegPathPtr = RegPath + _tcslen(RegPath);

    DEBUGMSG(ZONE_ACTIVE,
        (TEXT("DEVICE!StartDriver walking HLM\\%s.\r\n"), RegPath));
    
    //
    // Walk the device keys under the "MULTI" key, calling StartOneDriver for
    // each one.
    //
    bRet = FALSE;
    RegEnum = 0;
    ValLen = REG_PATH_LEN - (RegPathPtr - RegPath);  // ValLen is in TCHAR units, not bytes
    while (1) {
        ValLen1 = ValLen;
        status = RegEnumKeyEx(
                    MultiKey,
                    RegEnum,
                    RegPathPtr,
                    &ValLen1,
                    NULL,
                    NULL,
                    NULL,
                    NULL);

        if (status != ERROR_SUCCESS) {
            DEBUGMSG(ZONE_ACTIVE|ZONE_ERROR,
                     (TEXT("DEVICE!StartDriver RegEnumKeyEx(%s) returned %d.\r\n"),
                      RegPath, status));
            RegCloseKey(MultiKey);
            return bRet;
        }

        DEBUGMSG(ZONE_ACTIVE|ZONE_ERROR,
            (TEXT("DEVICE!StartDriver Loading %s.\r\n"), RegPath));
        if (StartOneDriver(RegPath, PnpId, LoadOrder, RegEnum, hSock)) {
            bRet = TRUE;
        }
        RegEnum++;
    }
    
    return bRet;  // should never get here.

}   // StartDriver

//
// Function to load device drivers for built-in devices.
//
VOID
InitDevices(VOID)
{
    HKEY BuiltInKey;
    HKEY DevKey;
    DWORD DevLoadOrder;
    DWORD LoadOrder;
    DWORD NumDevKeys;
    DWORD RegEnum;
    DWORD status;
    DWORD ValType;
    DWORD ValLen;
    BOOL  bKeepLib;
    TCHAR DevDll[DEVDLL_LEN];
    TCHAR DevEntry[DEVENTRY_LEN];
    TCHAR DevName[DEVNAME_LEN];
    TCHAR RegPath[REG_PATH_LEN];
    TCHAR * RegPathPtr;
    HMODULE hDevDll;
    PFN_DEV_ENTRY DevEntryFn;
    CARD_SOCKET_HANDLE hSock;

    //
    // Open the built-in device registry key
    //
    status = RegOpenKeyEx(
                HKEY_LOCAL_MACHINE,
                s_BuiltInKey,
                0,
                0,
                &BuiltInKey);
    if (status) {
        DEBUGMSG(ZONE_BUILTIN|ZONE_ERROR,
            (TEXT("DEVICE!InitDevices RegOpenKeyEx(BuiltIn) returned %d.\r\n"),
            status));
        return;
    }

    //
    // See how many built-in devices there are
    //
    RegEnum = sizeof(DevDll);
    status = RegQueryInfoKey(
                    BuiltInKey,
                    DevDll,         // class name buffer (lpszClass)
                    &RegEnum,       // ptr to length of class name buffer (lpcchClass)
                    NULL,           // reserved
                    &NumDevKeys,    // ptr to number of subkeys (lpcSubKeys)
                    &ValType,       // ptr to longest subkey name length (lpcchMaxSubKeyLen)
                    &ValLen,        // ptr to longest class string length (lpcchMaxClassLen)
                    &LoadOrder,     // ptr to number of value entries (lpcValues)
                    &DevLoadOrder,  // ptr to longest value name length (lpcchMaxValueNameLen)
                    &ValLen,        // ptr to longest value data length (lpcbMaxValueData)
                    NULL,           // ptr to security descriptor length
                    NULL);          // ptr to last write time
    if (status != ERROR_SUCCESS) {
        DEBUGMSG(ZONE_BUILTIN|ZONE_ERROR,
            (TEXT("DEVICE!InitDevices RegQueryInfoKey(Class) returned %d.\r\n"),
            status));
        goto id_end;
    }
    DEBUGMSG(ZONE_BUILTIN,
        (TEXT("DEVICE!InitDevices %d devices to load\r\n"), NumDevKeys));

    //
    // Setup registry path name string
    //
    _tcscpy(RegPath, s_BuiltInKey);
    RegPathPtr = RegPath + _tcslen(RegPath);
    *RegPathPtr = (TCHAR)'\\';
    RegPathPtr++;   // leave this pointing after the '\\'

    //
    // Read the built-in device list from the registry and start the drivers
    // according to their load order.
    //
    RegEnum = 0;
    LoadOrder = 0;
    DEBUGMSG(ZONE_BUILTIN,
        (TEXT("DEVICE!InitDevices LoadOrder = %d\r\n"), LoadOrder));
    while (NumDevKeys) {
        ValLen = sizeof(DevName) / sizeof(TCHAR);
        status = RegEnumKeyEx(
                    BuiltInKey,
                    RegEnum,
                    DevName,
                    &ValLen,
                    NULL,
                    NULL,
                    NULL,
                    NULL);

        if (status != ERROR_SUCCESS) {
            //
            // Assume all keys have been enumerated and start over using the
            // next load order.
            //
            RegEnum = 0;
            LoadOrder++;
            DEBUGMSG(ZONE_BUILTIN,
                (TEXT("DEVICE!InitDevices LoadOrder = %d\r\n"), LoadOrder));
            if (LoadOrder == MAX_LOAD_ORDER) {
                goto id_end;
            }
            continue;
        }

        status = RegOpenKeyEx(
                    BuiltInKey,
                    DevName,
                    0,
                    0,
                    &DevKey);
        if (status != ERROR_SUCCESS) {
            DEBUGMSG(ZONE_BUILTIN|ZONE_ERROR,
                (TEXT("DEVICE!InitDevices RegOpenKeyEx(%s) returned %d\r\n"),
                DevName, status));
            goto id_next_dev1;
        }

        //
        // Check the load order (required)
        //
        ValLen = sizeof(DevLoadOrder);
        status = RegQueryValueEx(
                    DevKey,
                    DEVLOAD_LOADORDER_VALNAME,
                    NULL,
                    &ValType,
                    (PUCHAR)&DevLoadOrder,
                    &ValLen);
        if (status != ERROR_SUCCESS) {
            DEBUGMSG(ZONE_BUILTIN|ZONE_ERROR,
                (TEXT("DEVICE!InitDevices RegQueryValueEx(%s\\LoadOrder) returned %d\r\n"),
                DevName, status));
            goto id_next_dev;
        }

        if (DevLoadOrder != LoadOrder) {
            goto id_next_dev;   // Don't load this device now.
        }

        //
        // If the entrypoint value exists, then devload will load the dll and call the
        // entrypoint function.  The dll device must then call RegisterDevice.
        //
        ValLen = sizeof(DevEntry);
        status = RegQueryValueEx(
                    DevKey,
                    DEVLOAD_ENTRYPOINT_VALNAME,
                    NULL,
                    &ValType,
                    (PUCHAR)DevEntry,
                    &ValLen);
        if (status != ERROR_SUCCESS) {
            goto id_register;
        }

        //
        // If the keeplib value is present, then do not call FreeLibrary after
        // calling the device's specified entrypoint.
        //
        ValLen = sizeof(DevDll);
        bKeepLib = (RegQueryValueEx(
                    DevKey,
                    DEVLOAD_KEEPLIB_VALNAME,
                    NULL,
                    &ValType,
                    (PUCHAR)DevDll,
                    &ValLen) == ERROR_SUCCESS) ? TRUE:FALSE;

        //
        // Read the DLL name (required)
        //
        ValLen = sizeof(DevDll);
        status = RegQueryValueEx(
                    DevKey,
                    s_DllName_ValName,
                    NULL,
                    &ValType,
                    (PUCHAR)DevDll,
                    &ValLen);
        if (status != ERROR_SUCCESS) {
            DEBUGMSG(ZONE_BUILTIN|ZONE_ERROR,
                (TEXT("DEVICE!InitDevices RegQueryValueEx(%s\\DllName) returned %d\r\n"),
                DevName, status));
            goto id_next_dev;
        }

        //
        // Load the device now.
        //
        hDevDll = LoadDriver(DevDll);
        if (hDevDll == NULL) {
            DEBUGMSG(ZONE_BUILTIN|ZONE_ERROR,
                (TEXT("DEVICE!InitDevices LoadDriver(%s) failed %d\r\n"),
                DevDll, GetLastError()));
            goto id_next_dev;
        }

        DevEntryFn = (PFN_DEV_ENTRY)GetProcAddress(hDevDll, DevEntry);
        if (DevEntryFn == NULL) {
            DEBUGMSG(ZONE_BUILTIN|ZONE_ERROR,
                (TEXT("DEVICE!InitDevices GetProcAddr(%s, %s) failed %d\r\n"),
                DevDll, DevEntry, GetLastError()));
            FreeLibrary(hDevDll);
            goto id_next_dev;
        }

        //
        // Finally, call the device's initialization entrypoint
        //
        _tcscpy(RegPathPtr, DevName);
        (DevEntryFn)(RegPath);
        NumDevKeys--;
        if (bKeepLib == FALSE) {
            FreeLibrary(hDevDll);
        }
        goto id_next_dev;


id_register:
        //
        // The device key did not contain an entrypoint value.
        // This means the device wants devload to call RegisterDevice for it.
        //
        _tcscpy(RegPathPtr, DevName);
        hSock.uSocket = 0xff;   // This indicates to StartDriver to not
        hSock.uFunction = 0xff; // add the socket value in the active key

        StartDriver(
            RegPath,
            NULL,           // BuiltIn devices have no PNP Id
            LoadOrder,
            hSock
            );

        NumDevKeys--;

id_next_dev:
        RegCloseKey(DevKey);
id_next_dev1:
        RegEnum++;

    }   // while (more device keys to try)

id_end:
    RegCloseKey(BuiltInKey);
}   // InitDevices


//
// Called from device.c after it initializes.
//
void DevloadInit(void)
{
	DEBUGREGISTER(NULL);
    DEBUGMSG(ZONE_INIT, (TEXT("DEVICE!DevloadInit\r\n")));
    //
    // Delete the HLM\Drivers\Active key since there are no active devices at
    // init time.
    //
    RegDeleteKey(HKEY_LOCAL_MACHINE, s_ActiveKey);

    v_NextDeviceNum = 0;
    v_hTapiDLL = NULL;
    v_hCoreDLL = NULL;
    g_bSystemInitd = FALSE;
    InitPCMCIA();
    InitDevices();
    InitTAPIDevices();
}


//
// Called from device.c after the system has initialized.
//
void DevloadPostInit(void)
{
    SYSTEMINIT pfnCardSystemInit;

    if (g_bSystemInitd) {
        DEBUGMSG(ZONE_INIT, (TEXT("DEVICE!DevloadPostInit: multiple DLL_SYSTEM_STARTED msgs!!!\r\n")));
        return;
    }
    g_bSystemInitd = TRUE;

    DEBUGMSG(ZONE_INIT, (TEXT("DEVICE!DevloadPostInit\r\n")));

    //
    // Indicate to pcmcia.dll that the system has initialized.
    //
    pfnCardSystemInit = (SYSTEMINIT) GetProcAddress(v_hPcmciaDll, TEXT("CardSystemInit"));
    if (pfnCardSystemInit) {
        pfnCardSystemInit();
    }
}

⌨️ 快捷键说明

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