Jump to content

VB.NET & Windows API calls


Recommended Posts

I have a problem. The function I want to call is as follows:

VOID CALLBACK InstallHinfSection(
 HWND hwnd,
 HINSTANCE ModuleHandle,
 PCTSTR CmdLineBuffer,
 INT nCmdShow
);

My problem is I cannot figure out how to pass my string to CmdLineBuffer.

I've tried passing it as a string and I cannot figure the whole pointers in Visual Basic thing out.

Can anyone help me with this?

Edit: Here is how I'm currently declaring this function (I think CmdLineBuffer is wrong):

' Note ModuleHandle should be Nothing and nCmdShow should be 0.
Declare Auto Sub InstallHinfSection Lib "setupapi" Alias "InstallHinfSection" (ByVal hwnd As String, ByVal ModuleHandle As String, ByVal CmdLineBuffer As String, ByVal nCmdShow As Integer)

Link to comment
Share on other sites


The documentation of the function you're wanting to call is written specifically for a C / C++ environment.

However, you can achieve what you need done by making a call to the console using this syntax

RUNDLL32.EXE SETUPAPI.DLL,InstallHinfSection <section> <mode> <path>

Replace <section> with the type of installation

Replace <mode> with 128 or 132

replace <path> with the absolute path to the *.inf file

This will kick-off the installation using the *.inf file as the driver...

for more information see here - http://msdn.microsoft.com/library/default....hinfsection.asp

OR

you could just call the setupapi.dll and use the internal library, pass the values, and go from there.

Link to comment
Share on other sites

@HeartsOfWar: 1. I was using that before but I want to get rid of the need to call external applications like that.

2. That is what I'm doing but I don't seem to sending the write values.

@crahak: Thanks.

Basically, what I need to is, what is the Visual Basic equivilent (sp?) of C's "PCTSTR"? How can I pass the equivilent (sp?) of a "PCTSTR" in Visual Basic .NET?

At the moment, the function call works but then setupapi gives a message box saying "Installation failed". The input string is CORRECT and using the exact same input string but making an external call to rundll32 works.

If only it was a LPTSTR, it would work... How the hell do I convert a PCTSTR?

Thanks for your help though.

Link to comment
Share on other sites

From all the documentation I can find, you are doing everything right...

Here is what I've found....

VOID CALLBACK InstallHinfSection(
HWND hwnd,
HINSTANCE ModuleHandle,
PCTSTR CmdLineBuffer,
INT nCmdShow
);

Declare function InstallHinfSection Lib "setupapi" Alias "InstallHinfSection" (ByVal hwnd As String, ByVal ModuleHandle As String, ByVal CmdLineBuffer As String, ByVal nCmdShow As Integer) as long

The only thing I see different from yours is you declared yours as an Auto Sub, and you didn't include a 'As long' at the end.

I'm not sure if this helps or makes a difference, but I have also discovered that Visual Basic can use a BSTR in the place of a LPCSTR, so

ByVal CmdLineBuffer As String

is correct... definately.. no conversion needed

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...