Small Error -> vb6 Code to VB.net

Posted on 2009-04-26
Medium Priority
Last Modified: 2013-11-26
Here i am getting error. "As Any" cannot be used in Declare statements. Please clear all errors in this code..
Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Const KEY_WRITE = &H20006
Const REG_SZ = 1
Const KEY_HKCU = &H80000001 'long value for HKEY_CURRENT_USER
Sub SetRegistryValue(value As String)
    Dim handle As Long
    Dim strValue As String
    Dim retVal As Long
    ' Open the key, exit if not found
    If RegOpenKeyEx(KEY_HKCU, "Software\Microsoft\Internet Explorer\Main", 0, KEY_WRITE, handle) Then
        Exit Sub
    End If
    strValue = value
    retVal = RegSetValueEx(handle, "Display Inline Images", 0, REG_SZ, ByVal strValue, Len(strValue))
    ' Close the key and signal success
    RegCloseKey handle
End Sub
Public Function ShowImages()
    SetRegistryValue ("yes")
End Function
Public Function HideImages()
    SetRegistryValue ("no")
End Function

Open in new window

Question by:Yogesh_Agarwal
LVL 48

Expert Comment

ID: 24235275
You don't need to use API's to work with registry. You have classes included in Visual Studio to help you on that.
Check this examples:

Author Comment

ID: 24235500
but this code helps me to switch off loading of images in webbrowser control (IE) as i don know how to do it programatically. I want to change registry(switch of loading of image in IE programatically).. cud u please help me?

Accepted Solution

Aleksei_Malkov earned 2000 total points
ID: 24235508
Hi, agree with jpaulino

I'm not good at VB but
Code should look like the following:
    Sub SetRegistryValue(ByVal value As String)
        Dim strValue As String
        Dim regKey As Microsoft.Win32.RegistryKey
        ' Open the key, exit if not found
        regKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\Microsoft\Internet Explorer\Main", True)
        If regKey IsNot Nothing Then
            regKey.SetValue("Display Inline Images", strValue, Microsoft.Win32.RegistryValueKind.String)
            Exit Sub
        End If
    End Sub

Open in new window

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

LVL 70

Expert Comment

by:Éric Moreau
ID: 24236070
change it for a String in this case.
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 24236829
Right...if you want to keep the old API approach then change all Long to Integer, and replace As Any with the appropriate Type.

Author Closing Comment

ID: 31574638

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question