Solved

DeviceIoControl

Posted on 1997-03-30
10
332 Views
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.
0
Comment
Question by:faster
10 Comments
 
LVL 23

Expert Comment

by:chensu
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.

0
 
LVL 7

Author Comment

by:faster
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.
0
 
LVL 23

Expert Comment

by:chensu
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?

0
 
LVL 7

Author Comment

by:faster
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!

0
 
LVL 23

Expert Comment

by:chensu
ID: 1334303
To check whether a VXD is installed, you can call Win32 Registry functions to access the Registry of Windows 95:
\HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\InstalledFiles.
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!

0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 7

Author Comment

by:faster
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.

0
 

Expert Comment

by:goldsmit
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.

   FARPROC p;
   _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;
notfound:
   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)
0
 
LVL 7

Author Comment

by:faster
ID: 1334306

0
 

Accepted Solution

by:
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", ...).
0
 
LVL 7

Author Comment

by:faster
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.

0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
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. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now