Posted on 1997-03-30
Last Modified: 2013-12-03
I have a mouse driver, and an application that needs to send some information to the driver.  I use DeviceIoControl to do this. It works fine when the driver was installed.  However, when the driver is removed and the application calls CreateFile (in order to get the handle used by DeviceIoControl), it crashes.  I think it is due to the initialisation code of the driver which conflicts with the current mouse driver.  How shall I do with this problem?  Is there a way to determine whether a driver is being loaded by device manager of by the "CreateFile" API from the application?  Or how shall the application detects that the correct driver has not been loaded?

Thanks in advance.
Question by:faster
LVL 23

Expert Comment

ID: 1334299
How shall the application detects that the correct driver has not been loaded?

Call GetModuleHandle()

e.g., GetModuleHandle("mouse")

You can run HeapWalk to check the module name.


Author Comment

ID: 1334300
I am sorry, maybe I have not put my question clear enough.  My problem is that my application does not know whether the VXD is loaded or not, therefore, upon calling CreateFile, it will triger the initialisation code of the vxd, and therefore conflicts with the current mouse driver.  Calling "GetModuleHandle" does not seem to let the app know what mouse driver is currently running.
LVL 23

Expert Comment

ID: 1334301
Actually, I do not understand your question very clearly. Why do you need two mouse drivers? If the initialization code of the driver conflicts with the current mouse driver, how was it installed?

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.


Author Comment

ID: 1334302
Thank for your kind help.   Let me explain it more clearly.

I have a mouse minidriver, say "mymouse.vxd", which needs to communicate with my exe "myexe.exe".  This is needed because the vxd alone can not get all the job done and therefore it will send a message to myexe.exe so that the exe can take care of the rest.  In order to do this, I need to inform the vxd the handle of the window (belongs to the exe).  I use DeviceIoControl to do this.

When my driver (including the vxd and exe, the exe will load automatically) is installed, it works fine.  However, if the driver is removed, my vxd is still in the hard disk, and the exe is still running (the exe does not know that user has changed the driver).  The exe will call CreateFile, however, the PC crashes at this stage.  I guess this is because it cause my vxd intiialising and running again, then there are two mouse vxds and the system crashed.

So what I need is: let the exe detect that my vxd is not loaded, or: my driver has not been installed, or the vxd can know it is loaded by the exe, not by win95 itself.

Any suggestions?

Thanks again!

LVL 23

Expert Comment

ID: 1334303
To check whether a VXD is installed, you can call Win32 Registry functions to access the Registry of Windows 95:
For example, if mymouse.vxd is installed, there should be a key 'mymouse.vxd'. (You may run Registry Editor to see it.) It should work although I have never tried. Good Luck!


Author Comment

ID: 1334304
I am afraid this does not help.  All the drivers that have been installed will appear there, no matter whether it is currently being used.


Expert Comment

ID: 1334305
 There are a few methods I can think to try:

  First, pass a Window handle to the VxD of the application that is interested in the VxD.  When the VxD exits, it can call service SHELL_PostMessage to that Window and inform it that it is gone.  

  If you want all applications to get the message, then the VxD can invoke PostMessage and send a message that your application can trap on.  This requires the VxD locate the address of the PostMessage entry point in the system VM, and may require a helper driver.

  If your VxD has a protected mode entry point that allows Ring 3 applications access, you can use the following snippet of code to retrieve the entry point.  If the entry is not found, it will return a 0 and you can assume the VxD is not loaded.  You may even want to include a protected mode entry point if only for this purpose.

   _asm {
          push ds
          mov  ax,168Ah
          lds  si,pIDString
          xor  di,di
          mov  es,di
          int  2Fh
          pop  ds
          cmp  al,0
          jne  short notFound
          mov  word ptr [p],di
          mov  word ptr [p+2],es
   return p;
   return 0;

 in the code example,  pIDString is a char far* that is the ID string of the VxD.

  A combination of the above methods might be a good idea.  They would cover every concievable situation ie
  1) VxD removed in the middle of app execution (postmessage method, or ShellPostMessage)
  2) VxD not loaded when app starts (retrieving PM entry point method)

Author Comment

ID: 1334306


Accepted Solution

brien earned 200 total points
ID: 1334307
Gees, lots of rejections...  here's the right answer:

CreateFile("\\\\.\\mymouse", ...) will fail if the driver is not already in memory.  Use this if you want to get a handle to the device ONLY if it is already loaded.

CreateFile("\\\\.\\mymouse.vxd", ...) will load the driver if it is not already loaded into memory.  With this form you may use an absolute path such as CreateFile("\\\\.\\c:\\myapp\\mymouse.vxd", ...).

Author Comment

ID: 1334308
I am sorry to say that your answer is too late and I actually don't need it anymore since I already have my own solution.  Besides, now I don't have the environment to test your answer.  However, if your statement is true, it should solve my problem.  Thanks anyway.


Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL to ElasticSearch Query 1 636
VBA Error Since Excel 2016 x64 5 111
Visual Studio Debugging 3 132
SSRS troubles 4 48
This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question