Small Error -> vb6 Code to

Posted on 2009-04-26
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

    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

    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?
    LVL 3

    Accepted Solution

    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

    LVL 69

    Expert Comment

    by:Éric Moreau
    change it for a String in this case.
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    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


    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (…
    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now