Call Windows API from VB.Net?

  • Thread starter Thread starter Jack Black
  • Start date Start date
J

Jack Black

Hi, all!! Using VB.Net and VS/2003.

I'm trying to call standard Windows API calls from VB.NET, but keep getting
an "Unhandled Exception of type 'System.NotSupportedExtension' occurred in
myApp.exe". The call that's failing is CreateFile; all user types have been
converted to STRUCTURES, and all ANYs have been converted to a type that is
appropriate.

Any ideas? I'm sure this is something basic that I'm overlooking...
Thanks!
Jack
 
Hi Jack,

This is a very simple Api I am busy with now.

I hope this sample helps?

Cor

Public Structure SYSTEMTIME
Public Year As Short
Public Month As Short
Public DayOfWeek As Short
Public Day As Short
Public Hour As Short
Public Minute As Short
Public Second As Short
Public Milliseconds As Short
End Structure
Public Declare Sub GetSystemTime _
Lib "kernel32" Alias "GetSystemTime" _
(ByRef lpSystemTime As SYSTEMTIME)
Private Sub Form1_Load(ByVal sender _
As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
Dim systime As SYSTEMTIME
GetSystemTime(systime)
MsgBox(systime.Year.ToString())
End Sub
 
Hi,

Here is the api declare and structure.

Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" _
(ByVal lpFileName As String, ByVal dwDesiredAccess As Integer, _
ByVal dwShareMode As Integer, ByVal lpSecurityAttributes As
SECURITY_ATTRIBUTES, _
ByVal dwCreationDisposition As Integer, ByVal dwFlagsAndAttributes
As Integer, _
ByVal hTemplateFile As Intptr) As Intptr

Structure SECURITY_ATTRIBUTES
Dim nLength As Integer
Dim lpSecurityDescriptor As Integer
Dim bInheritHandle As Integer
End Structure

Ken
 
* "Jack Black said:
I'm trying to call standard Windows API calls from VB.NET, but keep getting
an "Unhandled Exception of type 'System.NotSupportedExtension' occurred in
myApp.exe". The call that's failing is CreateFile; all user types have been
converted to STRUCTURES, and all ANYs have been converted to a type that is
appropriate.

I assume that your declares and structures are not correct. Post your code.
 
Hi, all!! Using VB.Net and VS/2003.

I'm trying to call standard Windows API calls from VB.NET, but keep getting
an "Unhandled Exception of type 'System.NotSupportedExtension' occurred in
myApp.exe". The call that's failing is CreateFile; all user types have been
converted to STRUCTURES, and all ANYs have been converted to a type that is
appropriate.

Any ideas? I'm sure this is something basic that I'm overlooking...
Thanks!
Jack

I have a .dll written in C# (and the source code) for a set of shared
classes that have virtually all the api's. I did not write the classes and
do know where I obtained them. I THINK it was on gotdotnet.com. The api's
are grouped logically. Since they are shared classes, they are called
easily.

For example, to call the CreateFile method, you would use the following:

Win32.Kernel.CreateFile(....)

Of Course you can use the Imports statement to import any of the
namespaces.

I attempted to attach a zipped version of the source code but it was
rejected as too large (86K).

If you are interested, please send me an EMail (be sure to remove the anti
spam portion).

If someone knows who created these classes, I would like to know. I would
also like to find some public place that these classes could be made
available.
 
I'd like to see this as well...

cege at [[tavayn] [[[dot] [com]]]]

remove the '[ and ]
 
Back
Top