About IOCTL Of Intermediate Driver

Good afternoon,everyone.

I can’t get message from NDIS Intermediate Driver, and I don’t know why.
And the program as follows(When I debug the driver with WINDBG, the driver
runs well).Please tell me what’s wrong?

/*************************************
This is the user-mode program which calls DeviceIoControl

void CIoControlDlg::OnOK()
{
// TODO: Add extra validation here
TCHAR szBuffer[256];
DWORD dwReturned = 0;
BOOL bResult;
HANDLE m_hFile;
TCHAR data[256];

m_hFile = CreateFile(TEXT(“\\.\Passthru”),
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,
0);

if (m_hFile == INVALID_HANDLE_VALUE )
{
DWORD err=GetLastError();
AfxMessageBox(“driver not found”);
}

DWORD succ=GetLastError();

int tst=TESTIOCODE1;
bResult = DeviceIoControl (m_hFile,
tst,
data,
sizeof(data),
szBuffer,
sizeof(szBuffer),
&dwReturned,
NULL);
if(!bResult)
DWORD err=GetLastError();

CString out=szBuffer;
AfxMessageBox(out);

CDialog::OnOK();
}

/*******************************************************************
This is the kerner-mode program which process DEVICE_CONTROL

NTSTATUS
PtDispatch(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
)
/*++
Routine Description:

Process IRPs sent to this device.

Arguments:

DeviceObject - pointer to a device object
Irp - pointer to an I/O Request Packet

Return Value:

NTSTATUS - STATUS_SUCCESS always - change this when adding
real code to handle ioctls.

–*/
{
PIO_STACK_LOCATION irpStack;
NTSTATUS status = STATUS_SUCCESS;
ULONG ioControlCode;
PVOID ioBuffer;
ULONG inputBufferLength;
ULONG outputBufferLength;
NTSTATUS Status = STATUS_SUCCESS;
char *temp;
PCHAR data = “Device Driver !!!”; // This is device data
ULONG datalen = strlen(data)+1;// Length of data
including null

DBGPRINT((“==>Pt Dispatch\n”));
irpStack = IoGetCurrentIrpStackLocation(Irp);
ioBuffer = Irp->AssociatedIrp.SystemBuffer;
inputBufferLength =
irpStack->Parameters.DeviceIoControl.InputBufferLength;
outputBufferLength =
irpStack->Parameters.DeviceIoControl.OutputBufferLength;

switch (irpStack->MajorFunction) {
case IRP_MJ_CREATE:
DBGPRINT(“HANDLE IPR_MJ_CREATE\n”);
outputBufferLength = 0;
break;

case IRP_MJ_CLOSE:
DBGPRINT(“HANDLE IPR_MJ_CLOSE\n”);
outputBufferLength = 0;
break;

case IRP_MJ_CLEANUP:
DBGPRINT(“HANDLE IPR_MJ_CLEANUP\n”);
break;

case IRP_MJ_SHUTDOWN:
DBGPRINT(“HANDLE IPR_MJ_SHUTDOWN\n”);
break;

case IRP_MJ_DEVICE_CONTROL:

//
// get control code from stack and perform the operation
//

ioControlCode =
irpStack->Parameters.DeviceIoControl.IoControlCode;
strncpy(ioBuffer, data, dataLen);

outputBufferLength = datalen;

break;

case IRP_MJ_READ:

break;

default:
DBGPRINT(“DEFAULT IOCODE HANDL\n”);

Status = STATUS_UNSUCCESSFUL;
break;
}

Irp->IoStatus.Status = status;
Irp->IoStatus.Information = outputBufferLength;

IoCompleteRequest(Irp, IO_NO_INCREMENT);

DBGPRINT((“<== Pt Dispatch\n”));

return status;
}