I am trying to install minifilter driver using InstallHinfSection function. I have copied the .sys file and inf file to one directory in C drive.
When I install the driver from command prompt, using rundll32.exe it gets installed properly. I use following command :
RUNDLL32.EXE SETUPAPI.DLL,InstallHinfSection DefaultInstall 132 C:\scanner.inf
However when I try to perform same operation through my program, it fails. Here is the code I am using:
.
.
.
typedef VOID (CALLBACK *fptr)(HWND,HINSTANCE,PCTSTR,INT); //global
.
.
.
.
fptr InstHinfSec;
HMODULE hMod;
hMod = LoadLibrary(TEXT(“setupapi.dll”));
if(hMod == NULL)
{
MessageBox(hwnd,TEXT(“Failed to get access to setupapi.dll”),TEXT(“Error”),MB_OK);
return 0;
}
InstHinfSec = (fptr)GetProcAddress(hMod,TEXT(“InstallHinfSection”));
if(InstHinfSec == NULL)
{
MessageBox(hwnd,TEXT(“Failed to get access to InstallHinfSection function”),TEXT(“Error”),MB_OK);
return 0;
}
InstHinfSec(NULL,NULL,TEXT(“DefaultInstall 132 C:\scanner.inf”),0);
FreeLibrary(hMod);
.
.
…
In the above code , LoadLibrary and GetProcAddress work properly. But the driver fails to install.
Can anyone give some suggestion on what could be reason behind this.
Thank you in advance.
Hi,
rundll32 adds W at the end of function name and call InstallHinfSectionW
with proper params.
It may be problem if you are building it with UNICODE defined you are
passing wide char to an ANSI version of function.
To be sure that it is not the problem try update this 3 lines:
typedef VOID (CALLBACK *fptr)(HWND,HINSTANCE,PCSTR,INT); //global
InstHinfSec = (fptr)GetProcAddress(hMod,TEXT(“InstallHinfSectionA”));
InstHinfSec(NULL,NULL,“DefaultInstall 132 C:\scanner.inf”,0);
Jan
wrote in message news:xxxxx@ntfsd…
> I am trying to install minifilter driver using InstallHinfSection
function. I have copied the .sys file and inf file to one directory in C
drive.
> When I install the driver from command prompt, using rundll32.exe it gets
installed properly. I use following command :
>
> RUNDLL32.EXE SETUPAPI.DLL,InstallHinfSection DefaultInstall 132
C:\scanner.inf
>
> However when I try to perform same operation through my program, it fails.
Here is the code I am using:
>
> .
> .
> .
>
> typedef VOID (CALLBACK *fptr)(HWND,HINSTANCE,PCTSTR,INT);
//global
> .
> .
> .
> .
>
> fptr InstHinfSec;
> HMODULE hMod;
>
> hMod = LoadLibrary(TEXT(“setupapi.dll”));
> if(hMod == NULL)
> {
> MessageBox(hwnd,TEXT(“Failed to get access to
setupapi.dll”),TEXT(“Error”),MB_OK);
> return 0;
> }
>
> InstHinfSec = (fptr)GetProcAddress(hMod,TEXT(“InstallHinfSection”));
> if(InstHinfSec == NULL)
> {
> MessageBox(hwnd,TEXT(“Failed to get access to InstallHinfSection
function”),TEXT(“Error”),MB_OK);
> return 0;
> }
>
> InstHinfSec(NULL,NULL,TEXT(“DefaultInstall 132 C:\scanner.inf”),0);
>
> FreeLibrary(hMod);
>
> .
> .
> …
>
>
>
> In the above code , LoadLibrary and GetProcAddress work properly. But the
driver fails to install.
> Can anyone give some suggestion on what could be reason behind this.
> Thank you in advance.
>
Hello Jan,
Your suggestion has solved my problem.
I used InstallHinfSectionW and L instead of TEXT.
InstallHinfSectionW(NULL,NULL,L"DefaultInstall 132 C:\mps\model_generator\scanner.inf",0);
Thank you very much.