473,322 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

VB 2005 and Windows API calls

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/lib...k9(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

Sep 6 '07 #1
2 2414
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

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Sep 6 '07 #2
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.

"UnderCoverGuy" <Un***********@discussions.microsoft.comwrote in message
news:95**********************************@microsof t.com...
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/lib...k9(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

Sep 7 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Mike Owen | last post by:
Hi, I have just used the import Wizard to import a VS 2003 app to VS 2005. I have a lot of work to do to enable it to compile successfully with all the errors and warnings it gave me, but as a...
3
by: steve | last post by:
Hi All I have set a splash screen form as the application splash screen in VB.net 2005 I t runs fine but stays on top when my login screen appears How can I shut the splash screen down when...
2
by: Richard Collette | last post by:
Hi, I have a service, that runs perfectly when executed outside of the web service environment. When called as a web service I get the exception listed below sporadically. A call to the web...
1
by: Myster Edd | last post by:
I have a strange problem that I think deals with security on SQL 2005. I have a scheduled task that runs on a Windows 2000 machine. It calls a vb script which creates a connection to SQL Server. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.