www.pudn.com > 2410winceCE_l80t64.rar > wince.c


// 
// Copyright (c) Microsoft Corporation.  All rights reserved. 
// 
// 
// Use of this source code is subject to the terms of the Microsoft end-user 
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT. 
// If you did not accept the terms of the EULA, you are not authorized to use 
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your 
// install media. 
// 
/*++ 
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF 
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 
PARTICULAR PURPOSE. 
 
Module Name:   
 
wince.c 
 
Abstract:   
 
Windows CE specific functions for the CS8900A NDIS miniport driver. 
 
Functions: 
    DllEntry 
    AddKeyValues 
    Install_Driver 
 
Notes:  
 
 
--*/ 
#include  
#include  
#include  
#include  
#include  
 
#ifdef DEBUG 
 
// 
// These defines must match the ZONE_* defines in NE2000SW.H 
// 
#define DBG_ERROR      1 
#define DBG_WARN       2 
#define DBG_FUNCTION   4 
#define DBG_INIT       8 
#define DBG_INTR       16 
#define DBG_RCV        32 
#define DBG_XMIT       64 
 
#define ZONE_INIT		DEBUGZONE(0) 
 
 
DBGPARAM dpCurSettings = { 
    TEXT("CS8900A"), { 
    TEXT("Errors"),TEXT("Warnings"),TEXT("Functions"),TEXT("Init"), 
    TEXT("Interrupts"),TEXT("Receives"),TEXT("Transmits"),TEXT("Undefined"), 
    TEXT("Undefined"),TEXT("Undefined"),TEXT("Undefined"),TEXT("Undefined"), 
    TEXT("Undefined"),TEXT("Undefined"),TEXT("Undefined"),TEXT("Undefined") }, 
    DBG_INIT 
}; 
#endif  // DEBUG 
 
typedef struct _REG_VALUE_DESCR { 
    LPWSTR val_name; 
    DWORD  val_type; 
    PBYTE  val_data; 
} REG_VALUE_DESCR, * PREG_VALUE_DESCR; 
 
 
 
 
// Values for [HKEY_LOCAL_MACHINE\Comm\CS8900A] 
// and [HKEY_LOCAL_MACHINE\Comm\CS8900A1] 
REG_VALUE_DESCR CommKeyValues[] = { 
   (TEXT("DisplayName")), REG_SZ, (PBYTE)(TEXT("CS8900A Ethernet Driver")), 
   (TEXT("Group")), REG_SZ, (PBYTE)(TEXT("NDIS")), 
   (TEXT("ImagePath")), REG_SZ, (PBYTE)(TEXT("CS8900A.dll")), 
    NULL, 0, NULL 
}; 
 
/* 
   "BusNumber"=dword:0 
   "BusType"=dword:1 
   "DuplexMode"=dword:1 
   "MACAddress1"=dword:0000 
   "MACAddress2"=dword:0000 
   "MACAddress3"=dword:0000 
*/ 
// Values for [HKEY_LOCAL_MACHINE\Comm\CS8900A1\Parms] 
REG_VALUE_DESCR ParmKeyValues[] = { 
   (TEXT("BusNumber")), REG_DWORD, (PBYTE)0, 
   (TEXT("BusType")), REG_DWORD, (PBYTE)1, 
   (TEXT("DuplexMode")), REG_DWORD, (PBYTE)1, 
   (TEXT("MACAddress1")), REG_DWORD, (PBYTE)0,  
   (TEXT("MACAddress2")), REG_DWORD, (PBYTE)0,  
   (TEXT("MACAddress3")), REG_DWORD, (PBYTE)0,  
    NULL, 0, NULL 
}; 
 
// Values for [HKEY_LOCAL_MACHINE\Comm\CS8900A1] 
REG_VALUE_DESCR LinkageKeyValues[] = { 
   (TEXT("Route")), REG_MULTI_SZ, (PBYTE)(TEXT("CS8900A1\0")), 
    NULL, 0, NULL 
}; 
 
PREG_VALUE_DESCR Values[] = { 
    CommKeyValues, 
    CommKeyValues, 
    ParmKeyValues, 
    LinkageKeyValues 
}; 
 
LPWSTR KeyNames[] = { 
    (TEXT("Comm\\CS8900A")), 
    (TEXT("Comm\\CS8900A1")), 
    (TEXT("Comm\\CS8900A1\\Parms")), 
    (TEXT("Comm\\CS8900A\\Linkage")) 
}; 
 
 
// 
// Standard Windows DLL entrypoint. 
// Since Windows CE NDIS miniports are implemented as DLLs, a DLL entrypoint is 
// needed. 
// 
BOOL __stdcall 
DllEntry( 
  HANDLE hDLL, 
  DWORD dwReason, 
  LPVOID lpReserved 
) 
{ 
 
    switch (dwReason) { 
    case DLL_PROCESS_ATTACH: 
        DEBUGREGISTER(hDLL); 
        DEBUGMSG(ZONE_INIT, (TEXT("CS8900A: DLL_PROCESS_ATTACH\n"))); 
    	DisableThreadLibraryCalls((HMODULE) hDLL); 
        break; 
    case DLL_PROCESS_DETACH: 
        DEBUGMSG(ZONE_INIT, (TEXT("CS8900A: DLL_PROCESS_DETACH\n"))); 
        break; 
    } 
    return TRUE; 
} 
 
// 
// Add the specified key and its values to the registry under HKEY_LOCAL_MACHINE 
// 
BOOL 
AddKeyValues( 
    LPWSTR KeyName, 
    PREG_VALUE_DESCR Vals 
    ) 
{ 
    DWORD Status; 
    DWORD dwDisp; 
    HKEY hKey; 
    PREG_VALUE_DESCR pValue; 
    DWORD ValLen; 
    PBYTE pVal; 
    DWORD dwVal; 
    LPWSTR pStr; 
 
    Status = RegCreateKeyEx( 
                 HKEY_LOCAL_MACHINE, 
                 KeyName, 
                 0, 
                 NULL, 
                 REG_OPTION_NON_VOLATILE, 
                 0, 
                 NULL, 
                 &hKey, 
                 &dwDisp); 
 
    if (Status != ERROR_SUCCESS) { 
        return FALSE; 
    } 
 
    pValue = Vals; 
    while (pValue->val_name) { 
        switch (pValue->val_type) { 
        case REG_DWORD: 
            pVal = (PBYTE)&dwVal; 
            dwVal = (DWORD)pValue->val_data; 
            ValLen = sizeof(DWORD); 
            break; 
 
        case REG_SZ: 
            pVal = (PBYTE)pValue->val_data; 
            ValLen = (wcslen((LPWSTR)pVal) + 1)*sizeof(WCHAR); 
            break; 
 
        case REG_MULTI_SZ: 
            pStr = (LPWSTR)pValue->val_data; 
            dwVal = 0; 
            while (*pStr) { 
                dwDisp += wcslen(pStr) + 1; 
                dwVal += dwDisp; 
                pStr += dwDisp; 
            } 
            dwVal++; 
 
            ValLen = dwVal*sizeof(WCHAR); 
            pVal = pValue->val_data; 
            break; 
        } 
        Status = RegSetValueEx( 
                     hKey, 
                     pValue->val_name, 
                     0, 
                     pValue->val_type, 
                     pVal, 
                     ValLen 
                     ); 
        if (Status != ERROR_SUCCESS) { 
            RegCloseKey(hKey); 
            return FALSE; 
        } 
        pValue++; 
    } 
    RegCloseKey(hKey); 
    return TRUE; 
}   // AddKeyValues