Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Testing my first C driver

Testing my first C driver

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestiontestingbeta-testing
12 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C candogu

    Hi, I have a C file which contains a simple DbgPrint in DriverEntry but, when I build my project, I get 9 errors like C:\drvtest\src\testdriver.c : error CS2059: Syntax Error : ';' C:\drvtest\src\testdriver.c : error CS2059: Syntax Error : 'type' C:\drvtest\src\testdriver.c : error CS2059: Syntax Error : identifier DriverDispatch I use WDK and CodeBlocks as a C compiler. What is the problem? Please help. Thanks.

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #2

    Without seeing the actual code it is not easy to guess why you are seeing these syntax errors.

    Use the best guess

    C 1 Reply Last reply
    0
    • L Lost User

      Without seeing the actual code it is not easy to guess why you are seeing these syntax errors.

      Use the best guess

      C Offline
      C Offline
      candogu
      wrote on last edited by
      #3

      My code is below; #include "ntddk.h" NTSTATUS STDCALL DriverDispatch(IN PEDEVICE_OBJECT DeviceObject, IN PIRP Irp) { return STATUS_SUCCESS; } VOID STDCALL DriverUnload(IN PDRIVER_OBJECT DriverObject) { DbgPrint("Driver_Unload"); } NTSTATUS STDCALL DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegisterPath) { DbgPrint("Driver_Entry"); DriverObject->DriverUnload=DriverUnload; return STATUS_SUCCESS; } Thanks.

      L J 2 Replies Last reply
      0
      • C candogu

        My code is below; #include "ntddk.h" NTSTATUS STDCALL DriverDispatch(IN PEDEVICE_OBJECT DeviceObject, IN PIRP Irp) { return STATUS_SUCCESS; } VOID STDCALL DriverUnload(IN PDRIVER_OBJECT DriverObject) { DbgPrint("Driver_Unload"); } NTSTATUS STDCALL DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegisterPath) { DbgPrint("Driver_Entry"); DriverObject->DriverUnload=DriverUnload; return STATUS_SUCCESS; } Thanks.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #4

        Which line gives the error?

        Use the best guess

        C 1 Reply Last reply
        0
        • L Lost User

          Which line gives the error?

          Use the best guess

          C Offline
          C Offline
          candogu
          wrote on last edited by
          #5

          When I build the file, all the lines gives error. I think configuration files have errors. SOURCES and MAKEFILE. Thanks for your replies.

          L 2 Replies Last reply
          0
          • C candogu

            When I build the file, all the lines gives error. I think configuration files have errors. SOURCES and MAKEFILE. Thanks for your replies.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #6

            Sorry, I have no idea what that means, but I suspect you are missing some essential component in your build configuration.

            Use the best guess

            1 Reply Last reply
            0
            • C candogu

              My code is below; #include "ntddk.h" NTSTATUS STDCALL DriverDispatch(IN PEDEVICE_OBJECT DeviceObject, IN PIRP Irp) { return STATUS_SUCCESS; } VOID STDCALL DriverUnload(IN PDRIVER_OBJECT DriverObject) { DbgPrint("Driver_Unload"); } NTSTATUS STDCALL DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegisterPath) { DbgPrint("Driver_Entry"); DriverObject->DriverUnload=DriverUnload; return STATUS_SUCCESS; } Thanks.

              J Offline
              J Offline
              Jochen Arndt
              wrote on last edited by
              #7

              I'm not sure if this helps. But you may try (for all functions):

              // Function declaration with STDCALL calling convention
              NTSTATUS STDCALL DriverDispatch(IN PEDEVICE_OBJECT DeviceObject, IN PIRP Irp);

              // Function definition without calling convention
              NTSTATUS DriverDispatch(IN PEDEVICE_OBJECT DeviceObject, IN PIRP Irp)
              {
              return STATUS_SUCCESS;
              }

              L 1 Reply Last reply
              0
              • C candogu

                Hi, I have a C file which contains a simple DbgPrint in DriverEntry but, when I build my project, I get 9 errors like C:\drvtest\src\testdriver.c : error CS2059: Syntax Error : ';' C:\drvtest\src\testdriver.c : error CS2059: Syntax Error : 'type' C:\drvtest\src\testdriver.c : error CS2059: Syntax Error : identifier DriverDispatch I use WDK and CodeBlocks as a C compiler. What is the problem? Please help. Thanks.

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #8

                Have you included windows.h (or equivalent)? Have you tried commenting out statements until the compiler errors go away, and then introduce them back one by one until the compiler errors show up?

                "One man's wage rise is another man's price increase." - Harold Wilson

                "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

                L 1 Reply Last reply
                0
                • D David Crow

                  Have you included windows.h (or equivalent)? Have you tried commenting out statements until the compiler errors go away, and then introduce them back one by one until the compiler errors show up?

                  "One man's wage rise is another man's price increase." - Harold Wilson

                  "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                  "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #9

                  DavidCrow wrote:

                  Have you included windows.h?

                  In a driver? He needs wdm.h unles he is building an NT4 style driver.

                  ============================== Nothing to say.

                  1 Reply Last reply
                  0
                  • C candogu

                    When I build the file, all the lines gives error. I think configuration files have errors. SOURCES and MAKEFILE. Thanks for your replies.

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #10

                    So show us the SOURCES file.

                    ============================== Nothing to say.

                    1 Reply Last reply
                    0
                    • C candogu

                      Hi, I have a C file which contains a simple DbgPrint in DriverEntry but, when I build my project, I get 9 errors like C:\drvtest\src\testdriver.c : error CS2059: Syntax Error : ';' C:\drvtest\src\testdriver.c : error CS2059: Syntax Error : 'type' C:\drvtest\src\testdriver.c : error CS2059: Syntax Error : identifier DriverDispatch I use WDK and CodeBlocks as a C compiler. What is the problem? Please help. Thanks.

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #11

                      Good job you cant build it because it will BSOD anyway. You need to do this for starters in DriverEntry:

                      for (Index = 0 ; Index <= IRP\_MJ\_MAXIMUM\_FUNCTION ; Index++)
                      {
                          DriverObject->MajorFunction\[Index\] = MyDispatch;
                      }
                      
                      DriverObject->DriverExtension->AddDevice            = 0; // non PnP so dont set this
                      
                      DriverObject->DriverUnload                          = MyUnload;
                      

                      Your MyDispatch actually needs to do something with the Irps, set Information to 0, the status block to success and return success.

                      	Irp->IoStatus.Status		= STATUS\_SUCCESS;
                      	Irp->IoStatus.Information	= 0; 
                      	IoCompleteRequest(Irp, IO\_NO\_INCREMENT);
                      	return STATUS\_SUCCESS;
                      

                      You then need to make sure you are using the DDK (of WDK) compiler, as in actually install the entire DDK (WDK). I dont know what CodeBlocks is, I dont care, the DDK compiler is the one you must use. You need to get your SORCES file right, look at some of the samples that ship with the DDK (WDK). You then need a service entry in the registry in order to start your driver, either inf file or do it manually, then start it with 'net srart'.

                      ============================== Nothing to say.

                      1 Reply Last reply
                      0
                      • J Jochen Arndt

                        I'm not sure if this helps. But you may try (for all functions):

                        // Function declaration with STDCALL calling convention
                        NTSTATUS STDCALL DriverDispatch(IN PEDEVICE_OBJECT DeviceObject, IN PIRP Irp);

                        // Function definition without calling convention
                        NTSTATUS DriverDispatch(IN PEDEVICE_OBJECT DeviceObject, IN PIRP Irp)
                        {
                        return STATUS_SUCCESS;
                        }

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #12

                        No, you dont want to mess with that, leave the compiler do its thing.

                        ============================== Nothing to say.

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups