Discussion:
Global Variable in VXD
(too old to reply)
Arthur
2006-01-03 11:23:41 UTC
Permalink
I'm having a problem with "multiple instances" of a dynamic VXD. The
problem goes as follows:

I have a global variable in my VXD with the following declaration:

#pragma VxD_LOCKED_CODE_SEG
#pragma VxD_LOCKED_DATA_SEG

BOOLEAN IsInit = FALSE;

My VXD loads at boot time. On my INIT_COMPLETE routine, I do some
initialization code and set this global variable "IsInit" to TRUE.

The problem arrives when my GUI tries to establish communication with
the VDX. When the GUI uses CreateFile to open the VXD, the VXD receives
a DIOC_OPEN open message in the W32_DEVICEIOCONTROL routine. So far so
good. The problem is that the global variable "IsInit" has lost its
value! It's like every time an App calls CreateFile, Windows 98 creates
a new instance of my VXD for that application!

I have a similar driver for Windows 2K that works fine.

Is there a way to declare the global variable so that it will retain
its value during CreateFile calls? Is there a way to tell Windows not
to open new instances of my Vxd but to use the same instance every
time? What am I doing wrong?

Thanks in advance...
Arthur
2006-01-03 15:47:10 UTC
Permalink
A little update on my problem:

I found out that there are only two different instances of the VXD; one
that loads at boot time and other that is created using CreateFile. If
I open several GUIs that use CreateFile, all of then receive the same
instance of the VXD, and the global variable is shared among them. The
problem that remains is that the instance of the VXD that loads at boot
time still appears to have a different set of global variables.

Any help would be appreciated.
Uwe Solter
2006-01-04 01:20:46 UTC
Permalink
I assume that your "IsInit"-variable resides for some reason in the init
data segment which is discarded along with the
init code segment after your VxD has finished handling of the Init_Complete
message.
Check the map file generated by the linker to figure out where your variable
is located.

Cheers,

Don
Post by Arthur
I found out that there are only two different instances of the VXD; one
that loads at boot time and other that is created using CreateFile. If
I open several GUIs that use CreateFile, all of then receive the same
instance of the VXD, and the global variable is shared among them. The
problem that remains is that the instance of the VXD that loads at boot
time still appears to have a different set of global variables.
Any help would be appreciated.
Arthur
2006-01-04 10:23:05 UTC
Permalink
Uwe, thanks for your reply....

It seems to me that my variable "IsInit" is actually in locked data
segment. Here is an extract of my Map file:

Start Length Name Class
0001:00000000 00000020H .text CODE
0001:00000020 00002a00H _LDATA CODE
0001:00002a20 00003282H _LTEXT CODE
0002:00000000 000000ecH _PTEXT CODE
0003:00000000 00000020H _IDATA CODE
0003:00000020 00000228H _ITEXT CODE

Address Publics by Value Rva+Base Lib:Object
0001:00000068 MYDRIVER_DDB 00401068 MyDrivera.obj
0001:00000119 _IsInit 00401119 MyDriver.obj
0001:00002a50 _OnDriverInit 00403a50 f MyDriver.obj


The function "OnDriverInit" is called on INIT_COMPLETE and sets the
variable "IsInit" to TRUE.

Here is my .def file:

VXD MYDRIVER DYNAMIC

DESCRIPTION 'MyDriver'

SEGMENTS
_LPTEXT CLASS 'LCODE' PRELOAD NONDISCARDABLE
_LTEXT CLASS 'LCODE' PRELOAD NONDISCARDABLE
_LDATA CLASS 'LCODE' PRELOAD NONDISCARDABLE
_TEXT CLASS 'LCODE' PRELOAD NONDISCARDABLE
_TLS CLASS 'LCODE' PRELOAD NONDISCARDABLE
_ITEXT CLASS 'ICODE' DISCARDABLE
_IDATA CLASS 'ICODE' DISCARDABLE
_PTEXT CLASS 'PCODE' NONDISCARDABLE
_PDATA CLASS 'PDATA' NONDISCARDABLE SHARED
_STEXT CLASS 'SCODE' RESIDENT
_SDATA CLASS 'SCODE' RESIDENT
_16ICODE CLASS '16ICODE' PRELOAD DISCARDABLE
_RCODE CLASS 'RCODE'

EXPORTS
MYDRIVER_DDB @1

Any ideas ?

Loading...