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

📄 win1394.c

📁 winddk src目录下的WDM源码压缩!
💻 C
📖 第 1 页 / 共 2 页
字号:
/*++

Copyright (c) 1998  Microsoft Corporation

Module Name:

    win1394.c

Abstract

    1394 Test Application.

Author:

    Peter Binder (pbinder) 5/4/98

Revision History:
Date     Who       What
-------- --------- ------------------------------------------------------------
05/04/98 pbinder   birth, taken from old win1394
08/18/98 pbinder   changed for new dialogs
--*/

#define _WIN1394_C
#include "pch.h"
#include "tchar.h"
#undef _WIN1394_C

INT_PTR CALLBACK
SelectDeviceDlgProc(
    HWND        hDlg,
    UINT        uMsg,
    WPARAM      wParam,
    LPARAM      lParam
    )
{
    static HWND         hWndListBox;
    CHAR                tmpBuff[256];
    static INT          nIndex;
    ULONG               i;

    switch (uMsg) {

        case WM_INITDIALOG:

            // get a handle to our listbox
            hWndListBox = GetDlgItem(hDlg, IDC_1394_DEVICES);

            // let's plug all of our devices into the list box
            for (i=0;i<DeviceData.numDevices;i++) {

                strncpy (tmpBuff, DeviceData.deviceList[i].DeviceName, 255);
                tmpBuff[255] = '\0';
                SendMessage(hWndListBox, LB_ADDSTRING, 0, (LPARAM)tmpBuff);

                // see if this is our selected device
                if (lstrcmp(SelectedDevice, DeviceData.deviceList[i].DeviceName) == 0) {

                    // it is, lets select it...
                    SendMessage(hWndListBox, LB_SETCURSEL, 0, 0);
                }
            }

            // save the original device under test...
            nIndex = (INT)SendMessage(hWndListBox, LB_GETCURSEL, 0, 0);

            return(TRUE);

        case WM_COMMAND:

            switch (LOWORD(wParam)) {

                case IDC_1394_DEVICES:

                    if (HIWORD(wParam) != LBN_DBLCLK)
                        return(TRUE);

                    // just fall through here, it's the same thing if they
                    // double clicked on device

                case IDOK:

                    // get the new device under test
                    nIndex = (INT)SendMessage(hWndListBox,
                                              LB_GETCURSEL,
                                              0,
                                              0);

                    // make sure it's a valid index
                    if (nIndex != -1)
                        SelectedDevice = DeviceData.deviceList[nIndex].DeviceName;

                    EndDialog(hDlg, TRUE);
                    return(TRUE);

                case IDCANCEL:

                    EndDialog(hDlg, FALSE);
                    return(TRUE);

                default:
                    return(TRUE);
            }

            break;

        default:
            break;
    }

    return(FALSE);
} // SelectDeviceDlgProc

void
w1394_SelectTestDevice(
    HWND        hWnd
    )
{
    TRACE(TL_TRACE, (hWnd, "Enter w1394_SelectTestDevice\r\n"));

    if (DialogBox( (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE),
                   "SelectDevice",
                    hWnd,
                    SelectDeviceDlgProc
                    )) {

        TRACE(TL_TRACE, (hWnd, "Selected Device = %s\r\n", SelectedDevice));
    }

    TRACE(TL_TRACE, (hWnd, "Exit w1394_SelectTestDevice\r\n"));
    return;
} // w1394_SelectTestDevice


INT_PTR CALLBACK
SelectVirtualDeviceDlgProc(
    HWND        hDlg,
    UINT        uMsg,
    WPARAM      wParam,
    LPARAM      lParam
    )
{
    static HWND         hWndListBox;
    CHAR                tmpBuff[256];
    static INT          nIndex;
    ULONG               i;

    switch (uMsg) {

        case WM_INITDIALOG:

            // get a handle to our listbox
            hWndListBox = GetDlgItem(hDlg, IDC_1394_DEVICES);

            // let's plug all of our devices into the list box
            for (i=0;i<VirtDeviceData.numDevices;i++) {

                strncpy (tmpBuff, VirtDeviceData.deviceList[i].DeviceName, 255);
                tmpBuff[255] = '\0';
                SendMessage(hWndListBox, LB_ADDSTRING, 0, (LPARAM)tmpBuff);

                // see if this is our selected device
                if (lstrcmp(SelectedDevice, VirtDeviceData.deviceList[i].DeviceName) == 0) {

                    // it is, lets select it...
                    SendMessage(hWndListBox, LB_SETCURSEL, 0, 0);
                }
            }

            // save the original device under test...
            nIndex = (INT)SendMessage(hWndListBox, LB_GETCURSEL, 0, 0);

            return(TRUE);

        case WM_COMMAND:

            switch (LOWORD(wParam)) {

                case IDC_1394_DEVICES:

                    if (HIWORD(wParam) != LBN_DBLCLK)
                        return(TRUE);

                    // just fall through here, it's the same thing if they
                    // double clicked on device

                case IDOK:

                    // get the new device under test
                    nIndex = (INT)SendMessage(hWndListBox,
                                              LB_GETCURSEL,
                                              0,
                                              0);

                    // make sure it's a valid index
                    if (nIndex != -1)
                        SelectedDevice = VirtDeviceData.deviceList[nIndex].DeviceName;

                    EndDialog(hDlg, TRUE);
                    return(TRUE);

                case IDCANCEL:

                    EndDialog(hDlg, FALSE);
                    return(TRUE);

                default:
                    return(TRUE);
            }

            break;

        default:
            break;
    }

    return(FALSE);
} // SelectDeviceDlgProc

void
w1394_SelectVirtualTestDevice(
    HWND        hWnd
    )
{
    TRACE(TL_TRACE, (hWnd, "Enter w1394_SelectVirtualTestDevice\r\n"));

    if (DialogBox( (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE),
                    "SelectVirtualDevice",
                    hWnd,
                    SelectVirtualDeviceDlgProc
                    )) {

        TRACE(TL_TRACE, (hWnd, "Selected Device = %s\r\n", SelectedDevice));
    }
    
    TRACE(TL_TRACE, (hWnd, "Exit w1394_SelectVirtualTestDevice\r\n"));
    return;
} // w1394_SelectVirtualTestDevice

void
w1394_AddVirtualDriver (
    HWND        hWnd
    )
{
    VIRT_DEVICE     virtDevice;
    UCHAR           DeviceID[32] = "1394_VIRTUAL_DEVICE";
    ULONG           busNumber = 0;
    DWORD           dwRet;
    
    TRACE(TL_TRACE, (hWnd, "Enter w1394_AddVirtualDriver\r\n"));

    virtDevice.fulFlags = 0;
    virtDevice.InstanceID.HighPart = 0;
    virtDevice.InstanceID.LowPart = 0;
    virtDevice.DeviceID = DeviceID;

    do {
        dwRet = AddVirtualDriver (hWnd, &virtDevice, busNumber);

        if (dwRet == ERROR_SUCCESS) {

            TRACE(TL_TRACE, (hWnd, "Virtual Driver successfully added on 1394Bus%i\r\n", busNumber));
        }

        virtDevice.InstanceID.LowPart++;
        busNumber++;
        
    } while (dwRet == ERROR_SUCCESS);

    TRACE(TL_TRACE, (hWnd, "Exit w1394_AddVirtualDriver\r\n"));
    return;
}

void
w1394_RemoveVirtualDriver(
    HWND        hWnd
    )
{
    VIRT_DEVICE     virtDevice;
    UCHAR           DeviceID[32] = "1394_VIRTUAL_DEVICE";
    ULONG           busNumber = 0;
    DWORD           dwRet;
    
    TRACE(TL_TRACE, (hWnd, "Enter w1394_RemoveVirtualDriver\r\n"));

    virtDevice.fulFlags = 0;
    virtDevice.InstanceID.HighPart = 0;
    virtDevice.InstanceID.LowPart = 0;
    virtDevice.DeviceID = DeviceID;

    do {
        dwRet = RemoveVirtualDriver (hWnd, &virtDevice, busNumber);

        if (dwRet == ERROR_SUCCESS) {

            TRACE(TL_TRACE, (hWnd, "Virtual Driver successfully removed on 1394Bus%i\r\n", busNumber));
        }

        virtDevice.InstanceID.LowPart++;
        busNumber++;
        
    } while (dwRet == ERROR_SUCCESS);

    TRACE(TL_TRACE, (hWnd, "Exit w1394_RemoveVirtualDriver\r\n"));
    return;
}

INT_PTR CALLBACK
w1394_AboutDlgProc(
    HWND        hDlg,
    UINT        uMsg,
    WPARAM      wParam,
    LPARAM      lParam
    )
/*++

Routine Description:

    This is the DlgProc that we use for the About Box.

--*/
{
    HICON   hIcon;

    switch (uMsg) {

        case WM_INITDIALOG:

            // display initial icon
            hIcon = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_APP_ICON));

            SendDlgItemMessage(hDlg, IDI_APP_ICON, STM_SETIMAGE, (WPARAM) IMAGE_ICON, (LPARAM) hIcon);

            return TRUE;

        case WM_DESTROY:
            return TRUE;

        case WM_COMMAND:

            switch (LOWORD(wParam)) {

                case IDOK:
                    EndDialog(hDlg, TRUE);

                default:
                    return TRUE;
            }
            break;

        default:
            break;
    }

    return FALSE;
} // w1394_AboutDlgProc

#ifdef LOGGING
BOOL DoNT5Checking(void)
{
    TCHAR msg[]         = _T("You appear to be running an NT5 build with pool tagging turned OFF!.\n")
                          _T("Win1394 will not run on your machine unless you turn this on.");

    TCHAR msg2[]        = _T("You do not have Driver Verification enabled.\n")
                          _T("You need to enable this to run Win1394.");
                    
    TCHAR regKeyName[]  = _T("System\\CurrentControlSet\\Control\\Session Manager\\Memory Management");                  
    
    BOOL status = TRUE;
    OSVERSIONINFO os;
    //also need to check for the VerifyDrivers Key.
    HKEY hKey;

    os.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
    GetVersionEx(&os);

    //check for NT5
    if (os.dwMajorVersion == 5)
    {
        if (GetSystemMetrics(SM_DEBUG)) //checks for debug version of user
        {
            HKEY hKey;
            if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, regKeyName, 0, KEY_READ, &hKey))
            {
                //key exists - halfway there
                DWORD size = sizeof(DWORD);
                DWORD lpData;
                if (ERROR_SUCCESS != RegQueryValueEx(hKey, _T("PoolTag"), NULL, NULL, (LPBYTE)&lpData, &size))
                {
                    status = FALSE;
                    MessageBox(NULL, msg, "Win1394", MB_OK);
                } 
                RegCloseKey(hKey);
            }
        }

        if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, regKeyName, 0, KEY_READ, &hKey))
        {
            //key exists - halfway there
            DWORD size = 256;
            TCHAR lpData[256];
            if (ERROR_SUCCESS != RegQueryValueEx(hKey, _T("VerifyDrivers"), NULL, NULL, (LPBYTE)&lpData, &size))
            {
                status = FALSE;
                MessageBox(NULL, msg2, "Win1394", MB_OK);
            } 
            RegCloseKey(hKey);
        }

    }
    return status;
} 
#endif

LRESULT CALLBACK
w1394_AppWndProc(
    HWND    hWnd,
    UINT    iMsg,
    WPARAM  wParam,
    LPARAM  lParam
    )
/*++

Routine Description:

    This is the application main WndProc. Here we will handle
    all messages sent to the application.

--*/
{
    ULONG   i;

    switch(iMsg) {

        case WM_CREATE:

#ifdef LOGGING
            if (!DoNT5Checking()) {

                PostMessage(hWnd, WM_DESTROY, 0, 0);
                return DefWindowProc(hWnd, iMsg, wParam, lParam);
            }
#endif
            // create an edit control for the main app.
            g_hWndEdit = CreateWindow( "edit",
                                       NULL,
                                       WS_CHILD | WS_VISIBLE | WS_VSCROLL |
                                       WS_BORDER | ES_LEFT | ES_MULTILINE | ES_WANTRETURN |
                                       ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_READONLY,
                                       0,
                                       0,
                                       0,
                                       0,
                                       hWnd,
                                       (HMENU) EDIT_ID,
                                       g_hInstance,
                                       NULL
                                       );

            // set a timer, 1 time a second, we will print loopback test results with this

⌨️ 快捷键说明

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