Simple "Hello World" driver.

All development related issues welcome

Moderator: Moderator Team

Post Reply
Mikhail Masyagin
Posts: 1
Joined: Fri Feb 23, 2018 11:17 pm

Simple "Hello World" driver.

Post by Mikhail Masyagin »

Hello!
I tried to write simple driver for ReactOS.

Code: Select all

/* INCLUDES ******************************************************************/

#include <ntddk.h>
#include <debug.h>

/* FUNCTIONS *****************************************************************/

DRIVER_UNLOAD DriverUnload;
VOID
NTAPI
DriverUnload(IN PDRIVER_OBJECT DriverObject) {}

NTSTATUS
NTAPI
DriverEntry(IN PDRIVER_OBJECT DriverObject,
            IN PUNICODE_STRING RegistryPath) {
    /* For non-used parameter */
    UNREFERENCED_PARAMETER(RegistryPath);
    
    /* Setup the Driver Object */
    DriverObject->DriverUnload = DriverUnload;

    /* Log. */
    DPRINT1("Hello World.\n");
    
    /* Return success. */
    return STATUS_SUCCESS;
}

/* EOF */
It works on startup, but when I try to stop it, using "sc stop", there are some errors:
"No DriverUnload function!" in debug.log and "[SC] ControlService FAILED 1: ERROR_INVALID_FUNCTION" in cmd. I'm using ReactOS 0.5. Where is my mistake??
ThFabba
Developer
Posts: 293
Joined: Sun Jul 11, 2010 11:39 am

Re: Simple "Hello World" driver.

Post by ThFabba »

The driver you show should unload fine.
The message about missing DriverUnload makes me think you're not running the (exact build of the) driver you think you are. It's easy to (1) not correctly replace the .sys file on disk, or (2) forget about an instance in memory. So I'd suggest deleting the .sys file and service, rebooting ROS, then installing a clean build.
That said, driver unloading is something that's really buggy in ROS. I think we pretty much leak all drivers -- so unloading (once) might work, but re-loading the driver again afterwards probably won't.
On the plus side, it's not recommended to develop drivers in ROS anyway. They should be built & tested against Windows -- that way you don't end up writing code that relies on or works around ROS bugs :)
hbelusca
Developer
Posts: 1204
Joined: Sat Dec 26, 2009 10:36 pm
Location: Zagreb, Croatia

Re: Simple "Hello World" driver.

Post by hbelusca »

Huh yes, we don't really correctly unload drivers sadly :(( See https://jira.reactos.org/browse/CORE-8294 for some other details.
Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests