1

From this answer CoInternetIsFeatureEnabled in Delphi2010

Does anyone know how to stop the clicking sound. That doesn't appear to work in Delphi XE when I drop it into a separate pas file. There is some missing . and other reasons why it wont compile so im a bit stuck.

Here's what I did.

unit untUrlMon;

interface

uses
    Windows;

const
  GET_FEATURE_FROM_THREAD = $00000001;
  GET_FEATURE_FROM_PROCESS = $00000002;
  GET_FEATURE_FROM_REGISTRY = $00000004;
  GET_FEATURE_FROM_THREAD_LOCALMACHINE = $00000008;
  GET_FEATURE_FROM_THREAD_INTRANET = $00000010;
  GET_FEATURE_FROM_THREAD_TRUSTED = $00000020;
  GET_FEATURE_FROM_THREAD_INTERNET = $00000040;
  GET_FEATURE_FROM_THREAD_RESTRICTED = $00000080;

  SET_FEATURE_ON_THREAD = $00000001;
  SET_FEATURE_ON_PROCESS = $00000002;
  SET_FEATURE_IN_REGISTRY = $00000004;
  SET_FEATURE_ON_THREAD_LOCALMACHINE = $00000008;
  SET_FEATURE_ON_THREAD_INTRANET = $00000010;
  SET_FEATURE_ON_THREAD_TRUSTED = $00000020;
  SET_FEATURE_ON_THREAD_INTERNET = $00000040;
  SET_FEATURE_ON_THREAD_RESTRICTED = $00000080; 

type
  INTERNETFEATURELIST = (
    FEATURE_OBJECT_CACHING,
    FEATURE_ZONE_ELEVATION,
    FEATURE_MIME_HANDLING,
    FEATURE_MIME_SNIFFING,
    FEATURE_WINDOW_RESTRICTIONS,
    FEATURE_WEBOC_POPUPMANAGEMENT,
    FEATURE_BEHAVIORS,
    FEATURE_DISABLE_MK_PROTOCOL,
    FEATURE_LOCALMACHINE_LOCKDOWN,
    FEATURE_SECURITYBAND,
    FEATURE_RESTRICT_ACTIVEXINSTALL,
    FEATURE_VALIDATE_NAVIGATE_URL,
    FEATURE_RESTRICT_FILEDOWNLOAD,
    FEATURE_ADDON_MANAGEMENT,
    FEATURE_PROTOCOL_LOCKDOWN,
    FEATURE_HTTP_USERNAME_PASSWORD_DISABLE,
    FEATURE_SAFE_BINDTOOBJECT,
    FEATURE_UNC_SAVEDFILECHECK,
    FEATURE_GET_URL_DOM_FILEPATH_UNENCODED,
    FEATURE_TABBED_BROWSING,
    FEATURE_SSLUX,
    FEATURE_DISABLE_NAVIGATION_SOUNDS,
    FEATURE_DISABLE_LEGACY_COMPRESSION,
    FEATURE_FORCE_ADDR_AND_STATUS,
    FEATURE_XMLHTTP,
    FEATURE_DISABLE_TELNET_PROTOCOL,
    FEATURE_FEEDS,
    FEATURE_BLOCK_INPUT_PROMPTS,
    FEATURE_ENTRY_COUNT
  );

function CoInternetIsFeatureEnabled(FeatureEntry: INTERNETFEATURELIST; dwFlags: DWORD): HRESULT; stdcall; external 'urlmon.dll'

implementation

function CoInternetSetFeatureEnabled(FeatureEntry: INTERNETFEATURELIST; dwFlags: DWORD; fEnable: BOOL): HRESULT; stdcall; external 'urlmon.dll'

begin
  if CoInternetIsFeatureEnabled(FEATURE_DISABLE_NAVIGATION_SOUNDS, GET_FEATURE_FROM_PROCESS) = S_FALSE then
    CoInternetSetFeatureEnabled(FEATURE_DISABLE_NAVIGATION_SOUNDS, SET_FEATURE_ON_PROCESS, True); 
end;
Community
  • 1
  • 1
Wizzard
  • 12,582
  • 22
  • 68
  • 101
  • 2
    Did you call `CoInternalIsFeatureEnabled()` or just drop it into a unit and expect it to work without doing anything else? Please edit your question to show how you call the method. – Robert Love May 05 '11 at 02:48
  • If it works in D2010, it'll work in XE. Post everything, including how you call `CoInternetIsFeatureEnabled` from your own code. – Ken White May 05 '11 at 02:54
  • It doesn't compile is what I mean. I took that other code, added it to a pas file - as you can see there is now interface, uses etc. – Wizzard May 05 '11 at 04:45
  • What EXACTLY does not compile? What is the error message? – Remy Lebeau May 05 '11 at 05:59
  • Things that don't compile typically would produce a compiler error message, which points you to a line number. Can you provide that information? – Robert Love May 05 '11 at 20:54

2 Answers2

6

I'd imagine you need something like this:

unit untUrlMon;

implementation

uses
  Windows;

const
  SET_FEATURE_ON_PROCESS = $00000002;
  FEATURE_DISABLE_NAVIGATION_SOUNDS = 21;

function CoInternetSetFeatureEnabled(FeatureEntry: DWORD; dwFlags: DWORD; fEnable: BOOL): HRESULT; stdcall; external 'urlmon.dll';

initialization
  CoInternetSetFeatureEnabled(FEATURE_DISABLE_NAVIGATION_SOUNDS, SET_FEATURE_ON_PROCESS, True); 

end.
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
0

If you replace the final "end;" with "end." it should compile.

I believe you also need ";" after the two function declarations (after the "external 'urlmon.dll'" part).

The final "begin/end" is then run automatically in every program you include this unit in.

HeartWare
  • 7,464
  • 2
  • 26
  • 30