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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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?

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.


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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
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.…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

617 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