EldoS | Feel safer!

Software components for data protection, secure storage and transfer

rawdiskinst.dll in C#

Also by EldoS: SecureBlackbox
200+ components and classes for digital security, signing, encryption and secure networking.
#25496
Posted: 07/02/2013 05:11:43
by Isabelle JOUBERT (Standard support level)
Joined: 04/08/2013
Posts: 8

I try to install driver with the rawdiskinst.dll in C#.
With the RawDiskNet.dll all is OK, I can install and uninstall.

When I use rawdiskinst.dll, GetDriverStatus returns always false in DriverInstalled boolean and true as return code.
Here is my code:

[DllImport("rawdiskinst.dll", SetLastError = true, CharSet = CharSet.Auto)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetDriverStatusA(
string ProgramName,
[MarshalAs(UnmanagedType.Bool)] ref bool DriverInstalled,
[MarshalAs(UnmanagedType.U4)] ref int FileVersionHigh,
[MarshalAs(UnmanagedType.U4)] ref int FileVersionLow
);
ret = GetDriverStatusA(ProgramName, ref DriverInstalled, ref FileVersionHigh, ref FileVersionLow);

I installed also the driver via InstallDriverA and it is always the same.
Where is the problem?

Thanks in advance.
#25497
Posted: 07/02/2013 05:34:40
by Eugene Mayevski (EldoS Corp.)

Thank you for the report.

Your declaration is not exactly correct. First parameter is LPCSTR which is AnsiString. In your declaration it seems that ProgramName is treated as UnicodeString. I don't know how to write P/Invoke declaration correctly, but you can try setting Charset to Charset.ASCII. Alternatively use GetDriverStatusW function.


Sincerely yours
Eugene Mayevski
#25498
Posted: 07/02/2013 06:40:27
by Isabelle JOUBERT (Standard support level)
Joined: 04/08/2013
Posts: 8

Thank you for the quick answer, you pointed out the problem.
Here is the code, only W functions have to be used, if someone needs the exact syntax:

[DllImport("rawdiskinst.dll", SetLastError = true, CharSet = CharSet.Auto)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetDriverStatusW(
string ProgramName,
[MarshalAs(UnmanagedType.Bool)] ref bool DriverInstalled,
[MarshalAs(UnmanagedType.U4)] ref int FileVersionHigh,
[MarshalAs(UnmanagedType.U4)] ref int FileVersionLow

);

[DllImport("rawdiskinst.dll", SetLastError = true, CharSet = CharSet.Auto)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool InstallDriverW(
string DriverName,
string DriverName64,
string ProgramName,
[MarshalAs(UnmanagedType.Bool)] ref bool RebootNeeded
);

[DllImport("rawdiskinst.dll", SetLastError = true, CharSet = CharSet.Auto)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool UninstallDriverW(
string ProgramName,
[MarshalAs(UnmanagedType.Bool)] ref bool RebootNeeded
);

And all works!

Thanks.

Reply

Statistics

Topic viewed 4178 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!