📄 1394main.c
字号:
if (bAll) {
for (i = 0; i < 10; i++) {
_itoa(i, &BusName[11], 10);
hDevice = OpenDevice(NULL, BusName, FALSE);
if (hDevice != INVALID_HANDLE_VALUE) {
dwRet = DeviceIoControl( hDevice,
controlCode,
NULL,
0,
NULL,
0,
&dwBytesRet,
NULL
);
if (!dwRet) {
dwRet = GetLastError();
TRACE(TL_ERROR, (hWnd, "Error = 0x%x\r\n", dwRet));
}
else {
if (bMode) {
TRACE(TL_TRACE, (hWnd, "Diagnostic Mode enabled on %s\r\n", BusName));
}
else {
TRACE(TL_TRACE, (hWnd, "Diagnostic Mode disabled on %s\r\n", BusName));
}
}
CloseHandle(hDevice);
}
else {
goto Exit_DiagnosticMode;
}
}
}
else {
hDevice = OpenDevice(hWnd, szBusName, FALSE);
if (hDevice != INVALID_HANDLE_VALUE) {
// toggle diagnostic mode
dwRet = DeviceIoControl( hDevice,
controlCode,
NULL,
0,
NULL,
0,
&dwBytesRet,
NULL
);
if (!dwRet) {
dwRet = GetLastError();
TRACE(TL_ERROR, (hWnd, "Error = 0x%x\r\n", dwRet));
}
else {
if (bMode) {
TRACE(TL_TRACE, (hWnd, "Diagnostic Mode enabled on %s\r\n", szBusName));
}
else {
TRACE(TL_TRACE, (hWnd, "Diagnostic Mode disabled on %s\r\n", szBusName));
}
}
CloseHandle(hDevice);
}
}
Exit_DiagnosticMode:
TRACE(TL_TRACE, (hWnd, "Exit DiagnosticMode\r\n"));
} // DiagnosticMode
DWORD
WINAPI
RegisterClient(
HWND hWnd
)
{
BOOLEAN bReturn = TRUE;
TRACE(TL_TRACE, (SharedData->g_hWndEdit, "Enter RegisterClient\r\n"));
//
// we may be here before our main thread starts. block until its there
//
// WaitForSingleObject(SharedData->Started, 100000);
while (!SharedData->g_hWnd) {
Sleep(1000);
}
TRACE(TL_TRACE, (SharedData->g_hWndEdit, "SharedData->g_hWndEdit = 0x%x\r\n", SharedData->g_hWndEdit));
if (hWnd) {
SendMessage(SharedData->g_hWnd, WM_REGISTER_CLIENT, 0, (LPARAM)hWnd);
}
else {
bReturn = FALSE;
}
TRACE(TL_TRACE, (SharedData->g_hWndEdit, "Exit RegisterClient\r\n"));
return(bReturn);
} // RegisterClient
DWORD
WINAPI
DeRegisterClient(
HWND hWnd
)
{
BOOLEAN bReturn = TRUE;
TRACE(TL_TRACE, (SharedData->g_hWndEdit, "Enter DeRegisterClient\r\n"));
SendMessage(SharedData->g_hWnd, WM_DEREGISTER_CLIENT, 0, (LPARAM)hWnd);
TRACE(TL_TRACE, (SharedData->g_hWndEdit, "Exit DeRegisterClient\r\n"));
return(bReturn);
} // DeRegisterClient
DWORD
WINAPI
GetVirtualDeviceList(
PDEVICE_DATA DeviceData
)
{
BOOLEAN bReturn = TRUE;
TRACE(TL_TRACE, (SharedData->g_hWndEdit, "Enter GetVirtualDeviceList\r\n"));
//
// we may be here before our main thread starts. block until its there
//
while (!SharedData->g_hWndEdit) {
Sleep(1000);
}
CopyMemory( DeviceData, &SharedData->VDevDeviceData, sizeof(DEVICE_DATA));
TRACE(TL_TRACE, (SharedData->g_hWndEdit, "Exit GetVirtualDeviceList\r\n"));
return(bReturn);
} // GetVirtualDeviceList
DWORD
WINAPI
GetDeviceList(
PDEVICE_DATA DeviceData
)
{
BOOLEAN bReturn = TRUE;
TRACE(TL_TRACE, (SharedData->g_hWndEdit, "Enter GetDeviceList\r\n"));
//
// we may be here before our main thread starts. block until its there
//
while (!SharedData->g_hWndEdit) {
Sleep(1000);
}
CopyMemory( DeviceData, &SharedData->DiagDeviceData, sizeof(DEVICE_DATA));
TRACE(TL_TRACE, (SharedData->g_hWndEdit, "Exit GetDeviceList\r\n"));
return(bReturn);
} // GetDeviceList
ULONG
WINAPI
GetDiagVersion(
HWND hWnd,
PSTR szDeviceName,
PVERSION_DATA Version,
BOOL bMatch
)
{
HANDLE hDevice;
DWORD dwRet, dwBytesRet;
TRACE(TL_TRACE, (hWnd, "Enter GetDiagVersion\r\n"));
bMatch = FALSE;
hDevice = OpenDevice(hWnd, szDeviceName, FALSE);
if (hDevice != INVALID_HANDLE_VALUE) {
dwRet = DeviceIoControl( hDevice,
IOCTL_GET_DIAG_VERSION,
Version,
sizeof(VERSION_DATA),
Version,
sizeof(VERSION_DATA),
&dwBytesRet,
NULL
);
if (dwRet) {
dwRet = ERROR_SUCCESS;
if ((Version->ulVersion == DIAGNOSTIC_VERSION) &&
(Version->ulSubVersion == DIAGNOSTIC_SUB_VERSION)) {
bMatch = TRUE;
}
}
else {
dwRet = GetLastError();
TRACE(TL_ERROR, (hWnd, "Error = %d\r\n", dwRet));
}
// free up resources
CloseHandle(hDevice);
}
else {
dwRet = GetLastError();
TRACE(TL_ERROR, (hWnd, "Error = 0x%x\r\n", dwRet));
}
TRACE(TL_TRACE, (hWnd, "Exit GetDiagVersion\r\n"));
return(dwRet);
} // GetDiagVersion
DWORD
WINAPI
RemoveVirtualDriver (
HWND hWnd,
PVIRT_DEVICE pVirtualDevice,
ULONG BusNumber
)
{
HANDLE hDevice;
ULONG ulStrLen;
UCHAR BusName[16] = "\\\\.\\1394BUS";
PIEEE1394_API_REQUEST p1394ApiReq;
PIEEE1394_VDEV_PNP_REQUEST pDevPnpReq;
DWORD dwBytesRet;
DWORD dwRet;
TRACE(TL_TRACE, (NULL, "Enter RemoveVirtualDriver\r\n"));
if (!pVirtualDevice->DeviceID)
{
dwRet = ERROR_INVALID_PARAMETER;
goto Exit_RemoveVirtualDriver;
}
_itoa(BusNumber, &BusName[11], 10);
hDevice = OpenDevice(NULL, BusName, FALSE);
if (hDevice != INVALID_HANDLE_VALUE) {
ulStrLen = strlen(pVirtualDevice->DeviceID);
p1394ApiReq = LocalAlloc(LPTR, sizeof(IEEE1394_API_REQUEST)+ulStrLen);
p1394ApiReq->RequestNumber = IEEE1394_API_REMOVE_VIRTUAL_DEVICE;
p1394ApiReq->Flags = 0;
pDevPnpReq = &p1394ApiReq->u.RemoveVirtualDevice;
pDevPnpReq->fulFlags = pVirtualDevice->fulFlags;
pDevPnpReq->Reserved = 0;
pDevPnpReq->InstanceId = pVirtualDevice->InstanceID;
strncpy(&pDevPnpReq->DeviceId, pVirtualDevice->DeviceID, ulStrLen);
TRACE(TL_TRACE, (NULL, "p1394ApiReq = 0x%x\r\n", p1394ApiReq));
TRACE(TL_TRACE, (NULL, "pDevPnpReq = 0x%x\r\n", pDevPnpReq));
dwRet = DeviceIoControl( hDevice,
IOCTL_IEEE1394_API_REQUEST,
p1394ApiReq,
sizeof(IEEE1394_API_REQUEST)+ulStrLen,
NULL,
0,
&dwBytesRet,
NULL
);
if (!dwRet) {
dwRet = GetLastError();
TRACE(TL_ERROR, (NULL, "DeviceIoControl Error = 0x%x\r\n", dwRet));
}
else {
dwRet = ERROR_SUCCESS;
}
// free resources
CloseHandle (hDevice);
if (p1394ApiReq)
LocalFree(p1394ApiReq);
}
else {
dwRet = ERROR_INVALID_HANDLE;
}
Exit_RemoveVirtualDriver:
TRACE(TL_TRACE, (NULL, "Exit RemoveVirtualDriver\r\n"));
return dwRet;
}
DWORD
WINAPI
AddVirtualDriver (
HWND hWnd,
PVIRT_DEVICE pVirtualDevice,
ULONG BusNumber
)
{
HANDLE hDevice;
ULONG ulStrLen;
UCHAR BusName[16] = "\\\\.\\1394BUS";
PIEEE1394_API_REQUEST p1394ApiReq;
PIEEE1394_VDEV_PNP_REQUEST pDevPnpReq;
DWORD dwBytesRet;
DWORD dwRet;
TRACE(TL_TRACE, (NULL, "Enter AddVirtualDriverr\n"));
_itoa(BusNumber, &BusName[11], 10);
hDevice = OpenDevice(NULL, BusName, FALSE);
if (hDevice != INVALID_HANDLE_VALUE) {
ulStrLen = strlen(pVirtualDevice->DeviceID);
p1394ApiReq = LocalAlloc(LPTR, sizeof(IEEE1394_API_REQUEST)+ulStrLen);
p1394ApiReq->RequestNumber = IEEE1394_API_ADD_VIRTUAL_DEVICE;
p1394ApiReq->Flags = pVirtualDevice->fulFlags;
pDevPnpReq = &p1394ApiReq->u.AddVirtualDevice;
pDevPnpReq->fulFlags = pVirtualDevice->fulFlags;
pDevPnpReq->Reserved = 0;
pDevPnpReq->InstanceId = pVirtualDevice->InstanceID;
strncpy(&pDevPnpReq->DeviceId, pVirtualDevice->DeviceID, ulStrLen);
TRACE(TL_TRACE, (NULL, "pApiReq = 0x%x\r\n", p1394ApiReq));
TRACE(TL_TRACE, (NULL, "pDevPnpReq = 0x%x\r\n", pDevPnpReq));
dwRet = DeviceIoControl( hDevice,
IOCTL_IEEE1394_API_REQUEST,
p1394ApiReq,
sizeof(IEEE1394_API_REQUEST)+ulStrLen,
NULL,
0,
&dwBytesRet,
NULL
);
if (!dwRet) {
dwRet = GetLastError();
TRACE(TL_ERROR, (NULL, "DeviceIoControl Error = 0x%x\r\n", dwRet));
}
else {
dwRet = ERROR_SUCCESS;
}
// free resources
CloseHandle (hDevice);
if (p1394ApiReq)
LocalFree(p1394ApiReq);
}
else {
dwRet = ERROR_INVALID_HANDLE;
}
TRACE(TL_TRACE, (NULL, "Exit Add VirtualDriver\r\n"));
return dwRet;
}
DWORD
WINAPI
SetDebugSpew(
HWND hWnd,
ULONG SpewLevel
)
{
// set the TraceLevel
#if defined (DBG)
TRACE(TL_TRACE, (hWnd, "Debug Spew Set to %i\r\n", SpewLevel));
TraceLevel = SpewLevel;
return TraceLevel;
#endif
return -1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -