WCHAR *GetHardwareAddress(
    __in DHCP_CLIENT_UID phyAdd
)
{
    HRESULT HRes = S_OK;
    WCHAR *szPhysicalAddress = NULL;
    DWORD Size = 0;
    DWORD i=0, j=0, num0=0,num1=0,num2=0;

    if(phyAdd.Data != NULL && phyAdd.DataLength > 0)
    {
        // calculating the ecount of the hardware address string.
        // corressponding to each byte in the original string, there would be a hyphen and a '\0' character for the last one.
        HRes = DWordMult(3, phyAdd.DataLength, &Size);
        if (FAILED(HRes))
        {    
            return NULL;
        }
        // calculating the bcount of the hardware address string.
        HRes = DWordMult(Size, sizeof(WCHAR), &Size);
        if (FAILED(HRes))
        {
            return NULL;
        }
        // allocating the memory for the hardware address string. 
        szPhysicalAddress = (WCHAR *)malloc(Size);
        if (NULL == szPhysicalAddress)
        {
            return NULL;
        }
        memset(szPhysicalAddress, 0, Size);
        for (i=0; i<phyAdd.DataLength; i++)
        {
            num0 = phyAdd.Data[i];
            // getting the first hexadecimal character in the byte.
            num1 = num0 / 16;
            szPhysicalAddress[j++] = "0123456789ABCDEF"[num1];
            // getting the second hexadecimal character in the byte.
            num2 = num0 % 16;
            szPhysicalAddress[j++] = "0123456789ABCDEF"[num2];
            if (i < phyAdd.DataLength - 1)
            { 
                // adding the separator hyphen.
                szPhysicalAddress[j++] = L'-';
            }
        }
    }
    // adding the terminating null character.
    szPhysicalAddress[j] = L'\0';
    return szPhysicalAddress;
}
Exemplo n.º 2
0
////////////////////////////////////////////////////////////////////////////////
//
// Allocates and initializes OptType for OptItem.
//
static POPTTYPE CreateOptType(HANDLE hHeap, WORD wOptParams)
{
    POPTTYPE    pOptType = NULL;

    // Allocate memory from the heap for the OPTTYPE; the driver will take care of clean up.
    pOptType = (POPTTYPE) HeapAlloc(hHeap, HEAP_ZERO_MEMORY, sizeof(OPTTYPE));
    if(NULL != pOptType)
    {
        DWORD cbMemAllocSize;

        // Initialize OPTTYPE.
        pOptType->cbSize = sizeof(OPTTYPE);
        pOptType->Count = wOptParams;

        // Allocate memory from the heap for the OPTPARAMs for the OPTTYPE.

        // Call intsafe.h function to ensure there's no integer overflow or underflow
        if (SUCCEEDED(DWordMult(wOptParams, sizeof(OPTPARAM), &cbMemAllocSize)) &&
            (NULL != (pOptType->pOptParam = (POPTPARAM) HeapAlloc(hHeap, HEAP_ZERO_MEMORY, cbMemAllocSize))))
        {
            // Initialize the OPTPARAMs.
            for(WORD wCount = 0; wCount < wOptParams; wCount++)
            {
                pOptType->pOptParam[wCount].cbSize = sizeof(OPTPARAM);
            }
        }
        else
        {
            ERR("CreateOptType() failed to allocated memory for OPTPARAMs!\r\n");

            // Free allocated memory and return NULL.
            HeapFree(hHeap, 0, pOptType);
            pOptType = NULL;
        }
    }
    else
    {
        ERR("CreateOptType() failed to allocated memory for OPTTYPE!\r\n");
    }

    return pOptType;
}
Exemplo n.º 3
0
////////////////////////////////////////////////////////////////////////////////
//
// Creates and Initializes OptItems.
//
static POPTITEM CreateOptItems(HANDLE hHeap, DWORD dwOptItems)
{
    POPTITEM    pOptItems = NULL;
    DWORD       cbMemAllocSize;

    // Allocate memory for OptItems;

    // Call intsafe.h function to ensure there's no integer overflow or underflow
    if (SUCCEEDED(DWordMult(sizeof(OPTITEM), dwOptItems, &cbMemAllocSize)) &&
        (NULL != (pOptItems = (POPTITEM) HeapAlloc(hHeap, HEAP_ZERO_MEMORY, cbMemAllocSize))))
    {
        InitOptItems(pOptItems, dwOptItems);
    }
    else
    {
        ERR("CreateOptItems() failed to allocate memory for OPTITEMs!\r\n");
    }

    return pOptItems;
}
Exemplo n.º 4
0
LPWSTR
GetPlotHelpFile(
    PPRINTERINFO    pPI
)

/*++

Routine Description:

    This function setup the directory path for the driver Help file

Arguments:

    hPrinter    - Handle to the printer

Return Value:

    LPWSTR to the full path HelpFile, NULL if failed


Development History:

    01-Nov-1995 Wed 18:43:40 created


Revision History:


--*/

{
    PDRIVER_INFO_3  pDI3 = NULL;
    LPWSTR          pHelpFile = NULL;
    WCHAR           HelpFileName[MAX_HELPFILE_NAME];
    DWORD           cb;
    DWORD           cb2;
    DWORD           dwMemAllocSize = 0;
    HRESULT         hr = E_FAIL;

    if (pPI->pHelpFile) {

        return(pPI->pHelpFile);
    }

    if ((!GetPrinterDriver(pPI->hPrinter, NULL, 3, NULL, 0, &cb))              &&
            (GetLastError() == ERROR_INSUFFICIENT_BUFFER)                          &&
            (pDI3 = (PDRIVER_INFO_3)LocalAlloc(LMEM_FIXED, cb))                    &&
            (GetPrinterDriver(pPI->hPrinter, NULL, 3, (LPBYTE)pDI3, cb, &cb))      &&
            (pDI3->pHelpFile)                                                      &&
            (SUCCEEDED(DWordAdd((DWORD)wcslen(pDI3->pHelpFile), 1, &dwMemAllocSize)))     &&
            (SUCCEEDED(DWordMult(dwMemAllocSize, sizeof(WCHAR), &dwMemAllocSize))) &&
            (pHelpFile = (LPWSTR)LocalAlloc(LMEM_FIXED, dwMemAllocSize))) {

        hr = StringCchCopyW(pHelpFile, dwMemAllocSize / sizeof(WCHAR), (LPWSTR)pDI3->pHelpFile);

    } else if ((cb2 = LoadString(hPlotUIModule,
                                 IDS_HELP_FILENAME,
                                 &HelpFileName[1],
                                 COUNT_ARRAY(HelpFileName) - 1))            &&
               (SUCCEEDED(DWordAdd(cb2, 1, &cb2)))                          &&
               (SUCCEEDED(DWordMult(cb2, sizeof(WCHAR), &cb2)))             &&
               (!GetPrinterDriverDirectory(NULL, NULL, 1, NULL, 0, &cb))    &&
               (GetLastError() == ERROR_INSUFFICIENT_BUFFER)                &&
               (SUCCEEDED(DWordAdd(cb, cb2, &dwMemAllocSize)))              &&
               (pHelpFile = (LPWSTR)LocalAlloc(LMEM_FIXED, dwMemAllocSize)) &&
               (GetPrinterDriverDirectory(NULL,
                                          NULL,
                                          1,
                                          (LPBYTE)pHelpFile,
                                          cb,
                                          &cb))) {
        HelpFileName[0] = L'\\';

        hr = StringCchCatW(pHelpFile, dwMemAllocSize / sizeof(WCHAR), HelpFileName);
    }

    if (pDI3) {

        LocalFree((HLOCAL)pDI3);
        pDI3 = NULL;
    }

    if (pHelpFile && !SUCCEEDED(hr))
    {
        LocalFree(pHelpFile);
        pHelpFile = NULL;
    }

    PLOTDBG(DBG_SHOW_HELP, ("GetlotHelpFile: '%ws",
                            (pHelpFile) ? pHelpFile : L"Failed"));

    return(pPI->pHelpFile = pHelpFile);
}