|
-
October 30th, 2010, 10:09 PM
#4
Another Issue Starting the Driver...
EDIT: I found it. Need to do OpenService again after installing the driver.
Now that I fixed my stupid mistake I'm back to the original problem. When the driver is installed, everything works correctly, but if the driver is not installed when the program starts and the program programatically installs the driver, an error pops up that says "Can't start PortTalk Driver", but shutting down the program and restarting clears the problem and there are no further errors.
Here is the code that calls the code I posted earlier:
Code:
PortTalk_Handle = CreateFile("\\\\.\\PortTalk",
GENERIC_READ,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if(PortTalk_Handle == INVALID_HANDLE_VALUE)
{
/* Start or Install PortTalk Driver */
StartPortTalkDriver();
/* Then try to open once more, before failing */
PortTalk_Handle = CreateFile("\\\\.\\PortTalk",
GENERIC_READ,0,NULL,
OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
if(PortTalk_Handle == INVALID_HANDLE_VALUE)
{
MessageBox(NULL, "Can't access PortTalk Driver",
"DeviceIoControl", MB_OK);
return (char)-1; //WDO 6/23/10 Add cast
}
}
When the driver is installed, the second call to CreateFile fails and I get the error message. I doublechecked StartPortTalkDriver and InstallPortTalkDriver and the last call in both before returning is CloseServiceHandle, so there should be no open handle when CreateFile is called.
It can be worked around by shutting down the program and restarting, but that isn't a very clean way to do it. Why won't the second call to CreateFile work only when the driver is installed and never any other time?
I did verify that the service is not running on boot and the first run of the program does call StartPortTalkDriver. The problem only occurs when InstallPortTalkDriver is called.
Here is the relevant portion of InstallPortTalkDriver:
Code:
/* Open Handle to Service Control Manager */
SchSCManager = OpenSCManager (NULL,
NULL,
SC_MANAGER_ALL_ACCESS);
/* Create Service/Driver - This adds the appropriate registry keys in */
/* HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services - It doesn't */
/* care if the driver exists, or if the path is correct. */
schService = CreateService (SchSCManager,
"PortTalk",
"PortTalk",
SERVICE_ALL_ACCESS,
SERVICE_KERNEL_DRIVER,
SERVICE_DEMAND_START,
SERVICE_ERROR_NORMAL,
"System32\\Drivers\\PortTalk.sys",
NULL,
NULL,
NULL,
NULL,
NULL);
if (schService == NULL)
{
err = GetLastError();
if (err == ERROR_SERVICE_EXISTS)
{
MessageBox(NULL, "PortTalk driver install: Attempt to install driver failed", "DeviceIoControl", MB_OK);
}
else
MessageBox(NULL, "PortTalk driver install: Unknown error installing the driver", "DeviceIoControl", MB_OK);
}
/* Close Handle to Service Control Manager */
CloseServiceHandle (schService);
Last edited by wdolson; October 31st, 2010 at 01:13 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|