Hi everybody!
I’ve read the answers here, but according to them, I guess
I did not explain myself clearly…
I have an NDIS driver, which I start using StartService(), and
connect to it from my application using DefineDosDevice() and
then CreateFile().
It worked fine till now, but now - I have been asked to support
“multiple clients”, i.e.: multiple threads/processes can issue
a CreateFile() and connect to the driver.
The IoCreateDevice in the DriverEntry is:
IoCreateDevice(DriverObject,
sizeof(DEVICE_EXTENSION),
&UnicodeDeviceName,
FILE_DEVICE_TRANSPORT,
0, FALSE, &DeviceObject);
(as you can see - non exclusive).
I’m trying to run the SAME CODE that works now twice.
In both - the same lines are being called, the same symbolic
link name is used etc.
The 1st process succeeds in the CreateFile(), and the other does not.
Now, I tried to run them both with debuggers - I set a breakpoint
before the CreateFile() in both debuggers, and ran it.
When they both reached the CreateFile() line,
I stepped over it (f-10 in VC++), and then stepped over in the over
debugger - and it was successful in both cases!
BUT… When I put a breakpoint before the function the does
the CreateFile(), and steps over one, and then steps over
in the other debugger - it fails!
Another interesting thing, is that although the Symbolic Link name
is in the system (I checked with WinObj),
I must issue a DefineDosDevice() (that defines the already defined
symbolic link), and only then the CreateFile succeeds… otherwise -
it fails.
Please note that I tried all of the 4 combinations:
a. DefineDosDevice() in both processes
b. DefineDosDevice() in the 1st only
c. DefineDosDevice() in the 2nd only
d. DefineDosDevice() in no process
options c, d failed because the 1st process did not
succeed in the CreateFile()
options a,b - only the 1st process succeeded…
I’m desperate… I’ve been working on this stuff for a few
days - and nothing!!!
following is the function that does the CreateFile…
(You may recognize it as the Packet.sys sample from the NT-DDK…
)
Any ideas?
PVOID
PacketOpenAdapter(LPTSTR AdapterName)
{
LPADAPTER lpAdapter;
BOOLEAN Result;
c_debug (DEBUG_INFO, “Packet32: PacketOpenAdapter started”);
lpAdapter=(LPADAPTER)GlobalAllocPtr(
GMEM_MOVEABLE | GMEM_ZEROINIT,
sizeof(ADAPTER)
);
if (lpAdapter==NULL) {
c_error (0, “Packet32: PacketOpenAdapter GlobalAlloc Failed”);
return NULL;
}
wsprintf(
lpAdapter->SymbolicLink,
TEXT(“\\.\%s%s”),
DOSNAMEPREFIX,
&AdapterName[8]
);
Result=DefineDosDevice(
DDD_RAW_TARGET_PATH,
&lpAdapter->SymbolicLink[4],
AdapterName);
if (Result) {
lpAdapter->hFile=CreateFile(lpAdapter->SymbolicLink,
GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_ALWAYS,
FILE_FLAG_OVERLAPPED,
0);
if (lpAdapter->hFile != INVALID_HANDLE_VALUE) {
return lpAdapter;
}
else {
int x=GetLastError();
c_error (x, “Packet32: PacketOpenAdapter Could not open adapter”);
}
}
GlobalFreePtr(lpAdapter);
return NULL;
}
Note: c_debug and c_error are my macros for debugging… u may ignore
them…
thanks in advance,
- Barak
-----Original Message-----
From: Barak Mandelovich [mailto:xxxxx@conduct.com]
Sent: Tuesday, March 21, 2000 4:44 AM
To: NT Developers Interest List
Subject: [ntdev] problems using CreateFileHi everybody, and sorry for troubling you with
newbies questions, but I have a problem with CreateFile
that I just can’t figure out:I have a driver, to which I want to connect from my application,
using CreateFile(), and I have 2 processes that try to
attach to the driver.The first succeeds, and the second fails with error code #2
(ERROR_FILE_NOT_FOUND).The CreateFile line is this:
CreateFile(SymbolicLinkName,
GENERIC_WRITE | GENERIC_READ,
0,
NULL,
CREATE_ALWAYS,
FILE_FLAG_OVERLAPPED,0);