VB 2005 and Windows API calls

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Good afternoon. I need some basic help with VB. I haven't really used VB
since v6 and now I am using VS 2005 and I see a few things have changed (so
please excuse me if I am rusty).

I need to call a Windows API (RemoveControlByName - OCCACHE.DLL). So far, I
have followed http://msdn2.microsoft.com/en-us/library/172wfck9(VS.80).aspx
but keep getting the error "Name RemoveControlByName is not declared".

In VB, I have a CLASS of:

--------------------------------------------------------------------------------------

Imports Microsoft.VisualBasic

Public Class Class1

Public Declare Auto Function RemoveControlByName Lib "OCCACHE.DLL" Alias
"RemoveControlByName" ( _
ByVal lpszFile As DWORD, _
ByVal lpszCLSID As DWORD, _
ByVal lpszTypeLibID As DWORD, _
ByVal dwIsDistUnit As DWORD _
) As Long

End Class

--------------------------------------------------------------------------------------

For testing, my main form (Load) is:

--------------------------------------------------------------------------------------

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim RetVal As Integer
RetVal = RemoveControlByName("ActiveX Control", "CLSID" , , False,
True)
End
End Sub
End Class

--------------------------------------------------------------------------------------

When the form loads, I want the app to remove an ActiveX control called
"ActiveX Control". However, in the form I am given an error that the
RemoveControlByName statement is not declared. It used to be that I could
declare shared functions in modules attached to the project but I don't see
modules anymore.

Any help would be appreciated,

Thanks,
UCG
 
Public Declare Auto Function RemoveControlByName Lib "OCCACHE.DLL" Alias
"RemoveControlByName" ( _
ByVal lpszFile As DWORD, _
ByVal lpszCLSID As DWORD, _
ByVal lpszTypeLibID As DWORD, _
ByVal dwIsDistUnit As DWORD _
) As Long

Doesn't look right to me. Wrong number of parameters and types. I'd
declare it like this

Public Declare Auto Function RemoveControlByName Lib "OCCACHE.DLL" ( _
ByVal lpszFile As String, _
ByVal lpszCLSID As String, _
ByVal lpszTypeLibID As String, _
ByVal bForceRemove As Boolean, _
ByVal dwIsDistUnit As Integer _
) As Integer

It used to be that I could
declare shared functions in modules attached to the project but I don't see
modules anymore.

Modules still exist. Just change

Public Class Class1

to

Public Module Class1

above and see what happens. You can also keep it as a class and
specify the class name in the call

RetVal = Class1.RemoveControlByName(...



Mattias
 
What about something like...

<System.Runtime.InteropServices.DllImport("OCCACHE.dll")> _
Public Function RemoveControlByName(ByVal lpszFile As Int32, ByVal lpszCLSID
As Int32, ByVal lpszTypeLibID As Int32, ByVal dwIsDistUnit As Int32) As Long
End Function


Check the data types though, .NET doesn't support DWORD so I assumed they
were signed (Int32). However, if you need unsigned you can use UInt32.
 
Back
Top