0

I i am using code as

NTSTATUS
Register (_In_ FLT_FILESYSTEM_TYPE VolumeFilesystemType)
{
    NTSTATUS status = STATUS_FLT_DO_NOT_ATTACH;

    try {

        if (VolumeFilesystemType != FLT_FSTYPE_NTFS) {

            status = STATUS_NOT_SUPPORTED;
            leave;
        }

        ...

    }
    finally {
        if (!NT_SUCCESS(status)) {
            KdPrintEx((DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "AAFileFilter!Failed to register with status: %x\n", status));
            return STATUS_FLT_DO_NOT_ATTACH;
        }
        else
        {
            return  STATUS_SUCCESS;
        }
    }
}

I got C2220 for warning C4532 . If i changing code as

...
    finally {
        if (!NT_SUCCESS(status)) {
            KdPrintEx((DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "AAFileFilter!Failed to register with status: %x\n", status));
        }
    }

    if (NT_SUCCESS(status)) 
    {
        return STATUS_SUCCESS;
    }
    else
    {
        return STATUS_FLT_DO_NOT_ATTACH;
    }
}
  • Warning gone.. don't undestand what is the reason? The code should exactly works the same in both cases as for me. (I am using VS2013 with WindowsKernelModeDriver8.1 project in C)
Brans Ds
  • 4,039
  • 35
  • 64

2 Answers2

2

Exiting a try-finally statement using a return statement or the longjmp run-time function is considered abnormal termination. You probably get a warning about this and warnings are treated as errors.

PS. C support from Microsoft is crap.

tomato
  • 747
  • 5
  • 11
1

The most likely reason why you are getting compiler errors is because this is not valid C.

  • try does not exist in C (but in C++, Java, C#).
  • finally does not exist in C (but in Java, C#).
  • leave; is not valid C unless this is some macro you haven't posted.
  • Functions returning a value, without containing a return statement are invalid in C, since 1999. And they are stupid, since the invention of C.

You might have to enable non-standard language extensions, or otherwise switch to a strictly conforming C compiler. Visual Studio is infamous for its poor standard compliance.

Lundin
  • 195,001
  • 40
  • 254
  • 396
  • 1
    Those are extentions from MS. – tomato Jun 16 '14 at 11:33
  • This answer is not really relevant, yet was accepted. Baffling. – John Zwinck Jun 16 '14 at 12:06
  • @JohnZwinck Well, the question is tagged C, so this is a C answer. Maybe there was some compiler option needed to make this nonsense language compile? My general advise is to use a C compiler for C, and a nonsense compiler for nonsense. – Lundin Jun 16 '14 at 12:57