DWORD TDriver::InitDriver(LPCTSTR path)
{
if(initialized)
{
if(UnloadDriver()!=DRV_SUCCESS)
return DRV_ERROR_ALREADY_INITIALIZED;
}
driverPath=(LPTSTR)malloc(strlen(path)+1);
if(driverPath==NULL)
return DRV_ERROR_MEMORY;
strcpy(driverPath,path);
LPTSTR sPos1=strrchr(driverPath,(int)'\\');
if(sPos1==NULL)
sPos1=driverPath;
LPTSTR sPos2=strrchr(sPos1,(int)'.');
if(sPos2==NULL||sPos1>sPos2)
{
free(driverPath);
driverPath=NULL;
return DRV_ERROR_INVALID_PATH_OR_FILE;
}
driverName=(LPTSTR)malloc(sPos2-sPos1);
if(driverName==NULL)
{
free(driverPath);
driverPath=NULL;
return DRV_ERROE_MEMORY;
}
memcpy(driverName,sPos1+1,sPos2-sPos1-1);
driverName[sPos2-sPos1-1]=0;
driverDosName=(LPTSTR)malloc(strlen(driverName)+5);
if(driverDosName==NULL)
{
free(driverPath);
driverPath=NULL;
free(driverName);
driverName=NULL;
return DRV_ERROR_MEMORY;
}
sprintf(driverDosName,"\\\\.\\%s",driverName);
initialized=TRUE;
return DRV_SUCCESS;
}