Help converting Delphi code to VB

Hi can someone help me convert the following code into VB as my Delphi is terrible,

Source first, then unit to include (done in D5)...


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ComObj, ActiveX, Theme_TLB;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
{$R *.DFM}

const
  CLASS_ThemeManager:  TGUID =  '{2E17C0EF-2851-459B-A3C8-27A41D4BC9F7}';
  IID_IThemeManager:   TGUID =  '{04D5D56C-EEAF-4419-B786-300284D6BB5F}';

procedure TForm1.Button1Click(Sender: TObject);
var  pvTM:          IThemeManager;
     pvTheme:       ITheme;
     dwThemes:      Integer;
     dwTheme:       Integer;
begin

  // Such a hack....
  if (CoCreateInstance(CLASS_ThemeManager, nil, CLSCTX_ALL, IID_IThemeManager, pvTM) = S_OK) then
  begin
     // Resource protection
     try
        // Get the count of themes
        dwThemes:=Pred(pvTM.Length);
        // Walk the items looking for the classic style
        for dwTheme:=0 to dwThemes do
        begin
           // Get the theme
           pvTheme:=pvTM.Item[dwTheme];
           try
              // Check the theme name
              if (CompareText(String(pvTheme.DisplayName), 'Windows Classic') = 0) then
              begin
                 // Set the theme
                 pvTM.SelectedTheme:=pvTheme;
                 // Apply the theme
                 pvTM.ApplyNow;
                 // Done
                 break;
              end;
           finally
              // Release the theme
              pvTheme:=nil;
           end;
        end;
     finally
        // Release the theme manager interface
        pvTM:=nil;
     end;
  end;

end;

end.

------------------------------ Theme_tlb.pas -------------------------------

unit Theme_TLB;

{$TYPEDADDRESS OFF} // Unit must be compiled without type-checked pointers.
interface

uses Windows, ActiveX;

const
  // TypeLibrary Major and minor versions
  ThemeMajorVersion = 1;
  ThemeMinorVersion = 0;

  LIBID_Theme: TGUID = '{40643250-8D23-47FB-895C-EAF48E2C8892}';

  IID_ITheme: TGUID = '{A41C22EB-0F93-40AE-B7CE-37A4C4C81B01}';
  IID_IThemeScheme: TGUID = '{AA49D906-65B2-42D6-A26A-2EE03C83F839}';
  IID_IThemeStyle: TGUID = '{3672E804-D69D-43D8-AF58-F320B8D9AF32}';
  IID_IThemeSize: TGUID = '{72DD2E7F-21E5-46DC-8847-CDDCF58B6725}';
  IID_IThemeManager: TGUID = '{04D5D56C-EEAF-4419-B786-300284D6BB5F}';
  CLASS_ThemeManager: TGUID = '{2E17C0EF-2851-459B-A3C8-27A41D4BC9F7}';
  CLASS_Theme_: TGUID = '{F60691B4-3BD8-4F42-B2FD-20853C433A74}';
  CLASS_ThemeScheme: TGUID = '{1C995F92-244F-48AC-9784-4AF9586EBBBA}';
  CLASS_ThemeStyle: TGUID = '{AFCEFAC8-8097-4EE5-82DF-121202D95342}';
  CLASS_ThemeSize: TGUID = '{05AF76AC-4245-468F-AE35-6D233436937A}';
  IID_IThemePreview: TGUID = '{B63705F2-B2A2-401E-A20D-643E6B554A1D}';
  IID_IPropertyBag: TGUID = '{55272A00-42CB-11CE-8135-00AA004BB851}';
  IID_IErrorLog: TGUID = '{3127CA40-446E-11CE-8135-00AA004BB851}';
  CLASS_ThemePreview: TGUID = '{B7BBD408-F09C-4AA8-B65E-A00B8FE0F0B9}';

// *********************************************************************//
// Declaration of Enumerations defined in Type Library                    
// *********************************************************************//
// Constants for enum __MIDL_ITheme_0001
type
  __MIDL_ITheme_0001 = TOleEnum;
const
  BKDGT_CENTER = $00000000;
  BKDGT_TILE = $00000001;
  BKDGT_STRECH = $00000002;

// Constants for enum __MIDL_IThemeSize_0002
type
  __MIDL_IThemeSize_0002 = TOleEnum;
const
  SMS_BORDERWIDTH = $00000000;
  SMS_SCROLLWIDTH = $00000001;
  SMS_SCROLLHEIGHT = $00000002;
  SMS_CAPTIONWIDTH = $00000003;
  SMS_CAPTIONHEIGHT = $00000004;
  SMS_SMCAPTIONWIDTH = $00000005;
  SMS_SMCAPTIONHEIGHT = $00000006;
  SMS_MENUWIDTH = $00000007;
  SMS_MENUHEIGHT = $00000008;

// Constants for enum __MIDL_IThemeSize_0003
type
  __MIDL_IThemeSize_0003 = TOleEnum;
const
  CONTRAST_NORMAL = $00000000;
  CONTRAST_HIGHBLACK = $00000001;
  CONTRAST_HIGHWHITE = $00000002;

// Constants for enum __MIDL_IThemeSize_0001
type
  __MIDL_IThemeSize_0001 = TOleEnum;
const
  SMF_CAPTIONFONT = $00000000;
  SMF_SMCAPTIONFONT = $00000001;
  SMF_MENUFONT = $00000002;
  SMF_ICONTITLEFONT = $00000003;
  SMF_STATUSFONT = $00000004;
  SMF_MESSAGEFONT = $00000005;

type

// *********************************************************************//
// Forward declaration of types defined in TypeLibrary                    
// *********************************************************************//
  ITheme = interface;
  IThemeDisp = dispinterface;
  IThemeScheme = interface;
  IThemeSchemeDisp = dispinterface;
  IThemeStyle = interface;
  IThemeStyleDisp = dispinterface;
  IThemeSize = interface;
  IThemeSizeDisp = dispinterface;
  IThemeManager = interface;
  IThemeManagerDisp = dispinterface;
  IThemePreview = interface;
  IThemePreviewDisp = dispinterface;
  IPropertyBag = interface;
  IErrorLog = interface;

// *********************************************************************//
// Declaration of CoClasses defined in Type Library                      
// (NOTE: Here we map each CoClass to its Default Interface)              
// *********************************************************************//
  ThemeManager = IThemeManager;
  Theme_ = ITheme;
  ThemeScheme = IThemeScheme;
  ThemeStyle = IThemeStyle;
  ThemeSize = IThemeSize;
  ThemePreview = IThemePreview;


// *********************************************************************//
// Declaration of structures, unions and aliases.                        
// *********************************************************************//
  wireHWND = ^TGUID;
  PUserType1 = ^LOGFONTW; {*}
  POleVariant1 = ^OleVariant; {*}
  PUserType2 = ^TGUID; {*}

  enumBkgdTile = __MIDL_ITheme_0001;
  enumSystemMetricSize = __MIDL_IThemeSize_0002;
  enumThemeContrastLevels = __MIDL_IThemeSize_0003;
  enumSystemMetricFont = __MIDL_IThemeSize_0001;

  __MIDL___MIDL_itf_theme_0253_0004 = packed record
    lfHeight: Integer;
    lfWidth: Integer;
    lfEscapement: Integer;
    lfOrientation: Integer;
    lfWeight: Integer;
    lfItalic: Byte;
    lfUnderline: Byte;
    lfStrikeOut: Byte;
    lfCharSet: Byte;
    lfOutPrecision: Byte;
    lfClipPrecision: Byte;
    lfQuality: Byte;
    lfPitchAndFamily: Byte;
    lfFaceName: array[0..31] of Word;
  end;

  LOGFONTW = TGUID;

  __MIDL_IWinTypes_0009 = record
    case Integer of
      0: (hInproc: Integer);
      1: (hRemote: Integer);
  end;

  _RemotableHandle = packed record
    fContext: Integer;
    u: __MIDL_IWinTypes_0009;
  end;


// *********************************************************************//
// Interface: ITheme
// Flags:     (4544) Dual NonExtensible OleAutomation Dispatchable
// GUID:      {A41C22EB-0F93-40AE-B7CE-37A4C4C81B01}
// *********************************************************************//
  ITheme = interface(IDispatch)
    ['{A41C22EB-0F93-40AE-B7CE-37A4C4C81B01}']
    function  Get_DisplayName: WideString; safecall;
    procedure Set_DisplayName(const pbstrDisplayName: WideString); safecall;
    function  Get_Background: WideString; safecall;
    procedure Set_Background(const pbstrPath: WideString); safecall;
    function  Get_BackgroundTile: enumBkgdTile; safecall;
    procedure Set_BackgroundTile(pnTile: enumBkgdTile); safecall;
    function  Get_ScreenSaver: WideString; safecall;
    procedure Set_ScreenSaver(const pbstrPath: WideString); safecall;
    function  Get_VisualStyle: WideString; safecall;
    procedure Set_VisualStyle(const pbstrPath: WideString); safecall;
    function  Get_VisualStyleColor: WideString; safecall;
    procedure Set_VisualStyleColor(const pbstrPath: WideString); safecall;
    function  Get_VisualStyleSize: WideString; safecall;
    procedure Set_VisualStyleSize(const pbstrPath: WideString); safecall;
    function  GetPath(fExpand: WordBool): WideString; safecall;
    procedure SetPath(const bstrPath: WideString); safecall;
    function  GetCursor(const bstrCursor: WideString): WideString; safecall;
    procedure SetCursor(const bstrCursor: WideString; const bstrPath: WideString); safecall;
    function  GetSound(const bstrSoundName: WideString): WideString; safecall;
    procedure SetSound(const bstrSoundName: WideString; const bstrPath: WideString); safecall;
    function  GetIcon(const bstrIconName: WideString): WideString; safecall;
    procedure SetIcon(const bstrIconName: WideString; const bstrIconPath: WideString); safecall;
    property DisplayName: WideString read Get_DisplayName write Set_DisplayName;
    property Background: WideString read Get_Background write Set_Background;
    property BackgroundTile: enumBkgdTile read Get_BackgroundTile write Set_BackgroundTile;
    property ScreenSaver: WideString read Get_ScreenSaver write Set_ScreenSaver;
    property VisualStyle: WideString read Get_VisualStyle write Set_VisualStyle;
    property VisualStyleColor: WideString read Get_VisualStyleColor write Set_VisualStyleColor;
    property VisualStyleSize: WideString read Get_VisualStyleSize write Set_VisualStyleSize;
  end;

// *********************************************************************//
// DispIntf:  IThemeDisp
// Flags:     (4544) Dual NonExtensible OleAutomation Dispatchable
// GUID:      {A41C22EB-0F93-40AE-B7CE-37A4C4C81B01}
// *********************************************************************//
  IThemeDisp = dispinterface
    ['{A41C22EB-0F93-40AE-B7CE-37A4C4C81B01}']
    property DisplayName: WideString dispid 200;
    property Background: WideString dispid 201;
    property BackgroundTile: enumBkgdTile dispid 202;
    property ScreenSaver: WideString dispid 203;
    property VisualStyle: WideString dispid 252;
    property VisualStyleColor: WideString dispid 253;
    property VisualStyleSize: WideString dispid 254;
    function  GetPath(fExpand: WordBool): WideString; dispid 250;
    procedure SetPath(const bstrPath: WideString); dispid 251;
    function  GetCursor(const bstrCursor: WideString): WideString; dispid 255;
    procedure SetCursor(const bstrCursor: WideString; const bstrPath: WideString); dispid 256;
    function  GetSound(const bstrSoundName: WideString): WideString; dispid 257;
    procedure SetSound(const bstrSoundName: WideString; const bstrPath: WideString); dispid 258;
    function  GetIcon(const bstrIconName: WideString): WideString; dispid 259;
    procedure SetIcon(const bstrIconName: WideString; const bstrIconPath: WideString); dispid 260;
  end;

// *********************************************************************//
// Interface: IThemeScheme
// Flags:     (4544) Dual NonExtensible OleAutomation Dispatchable
// GUID:      {AA49D906-65B2-42D6-A26A-2EE03C83F839}
// *********************************************************************//
  IThemeScheme = interface(IDispatch)
    ['{AA49D906-65B2-42D6-A26A-2EE03C83F839}']
    function  Get_DisplayName: WideString; safecall;
    procedure Set_DisplayName(const pbstrDisplayName: WideString); safecall;
    function  Get_Path: WideString; safecall;
    procedure Set_Path(const pbstrPath: WideString); safecall;
    function  Get_length: Integer; safecall;
    function  Get_item(varIndex: OleVariant): IThemeStyle; safecall;
    function  Get_SelectedStyle: IThemeStyle; safecall;
    procedure Set_SelectedStyle(const ppThemeStyle: IThemeStyle); safecall;
    function  AddStyle: IThemeStyle; safecall;
    property DisplayName: WideString read Get_DisplayName write Set_DisplayName;
    property Path: WideString read Get_Path write Set_Path;
    property length: Integer read Get_length;
    property item[varIndex: OleVariant]: IThemeStyle read Get_item;
    property SelectedStyle: IThemeStyle read Get_SelectedStyle write Set_SelectedStyle;
  end;

// *********************************************************************//
// DispIntf:  IThemeSchemeDisp
// Flags:     (4544) Dual NonExtensible OleAutomation Dispatchable
// GUID:      {AA49D906-65B2-42D6-A26A-2EE03C83F839}
// *********************************************************************//
  IThemeSchemeDisp = dispinterface
    ['{AA49D906-65B2-42D6-A26A-2EE03C83F839}']
    property DisplayName: WideString dispid 301;
    property Path: WideString dispid 302;
    property length: Integer readonly dispid 303;
    property item[varIndex: OleVariant]: IThemeStyle readonly dispid 304;
    property SelectedStyle: IThemeStyle dispid 305;
    function  AddStyle: IThemeStyle; dispid 350;
  end;

// *********************************************************************//
// Interface: IThemeStyle
// Flags:     (4544) Dual NonExtensible OleAutomation Dispatchable
// GUID:      {3672E804-D69D-43D8-AF58-F320B8D9AF32}
// *********************************************************************//
  IThemeStyle = interface(IDispatch)
    ['{3672E804-D69D-43D8-AF58-F320B8D9AF32}']
    function  Get_DisplayName: WideString; safecall;
    procedure Set_DisplayName(const pbstrDisplayName: WideString); safecall;
    function  Get_Name: WideString; safecall;
    procedure Set_Name(const pbstrName: WideString); safecall;
    function  Get_length: Integer; safecall;
    function  Get_item(varIndex: OleVariant): IThemeSize; safecall;
    function  Get_SelectedSize: IThemeSize; safecall;
    procedure Set_SelectedSize(const ppThemeSize: IThemeSize); safecall;
    function  AddSize: IThemeSize; safecall;
    property DisplayName: WideString read Get_DisplayName write Set_DisplayName;
    property Name: WideString read Get_Name write Set_Name;
    property length: Integer read Get_length;
    property item[varIndex: OleVariant]: IThemeSize read Get_item;
    property SelectedSize: IThemeSize read Get_SelectedSize write Set_SelectedSize;
  end;

// *********************************************************************//
// DispIntf:  IThemeStyleDisp
// Flags:     (4544) Dual NonExtensible OleAutomation Dispatchable
// GUID:      {3672E804-D69D-43D8-AF58-F320B8D9AF32}
// *********************************************************************//
  IThemeStyleDisp = dispinterface
    ['{3672E804-D69D-43D8-AF58-F320B8D9AF32}']
    property DisplayName: WideString dispid 400;
    property Name: WideString dispid 401;
    property length: Integer readonly dispid 402;
    property item[varIndex: OleVariant]: IThemeSize readonly dispid 403;
    property SelectedSize: IThemeSize dispid 404;
    function  AddSize: IThemeSize; dispid 450;
  end;

// *********************************************************************//
// Interface: IThemeSize
// Flags:     (4544) Dual NonExtensible OleAutomation Dispatchable
// GUID:      {72DD2E7F-21E5-46DC-8847-CDDCF58B6725}
// *********************************************************************//
  IThemeSize = interface(IDispatch)
    ['{72DD2E7F-21E5-46DC-8847-CDDCF58B6725}']
    function  Get_DisplayName: WideString; safecall;
    procedure Set_DisplayName(const pbstrDisplayName: WideString); safecall;
    function  Get_Name: WideString; safecall;
    procedure Set_Name(const pbstrName: WideString); safecall;
    function  Get_SystemMetricColor(nSysColorIndex: SYSINT): LongWord; safecall;
    procedure Set_SystemMetricColor(nSysColorIndex: SYSINT; pColorRef: LongWord); safecall;
    function  Get_SystemMetricSize(nSystemMetricIndex: enumSystemMetricSize): SYSINT; safecall;
    procedure Set_SystemMetricSize(nSystemMetricIndex: enumSystemMetricSize; pnSize: SYSINT); safecall;
    function  Get_WebviewCSS: WideString; safecall;
    function  Get_ContrastLevel: enumThemeContrastLevels; safecall;
    procedure Set_ContrastLevel(pContrastLevel: enumThemeContrastLevels); safecall;
    procedure GetSystemMetricFont(nFontIndex: enumSystemMetricFont; var pLogFontW: LOGFONTW); safecall;
    procedure PutSystemMetricFont(nFontIndex: enumSystemMetricFont; var pLogFontW: LOGFONTW); safecall;
    property DisplayName: WideString read Get_DisplayName write Set_DisplayName;
    property Name: WideString read Get_Name write Set_Name;
    property SystemMetricColor[nSysColorIndex: SYSINT]: LongWord read Get_SystemMetricColor write Set_SystemMetricColor;
    property SystemMetricSize[nSystemMetricIndex: enumSystemMetricSize]: SYSINT read Get_SystemMetricSize write Set_SystemMetricSize;
    property WebviewCSS: WideString read Get_WebviewCSS;
    property ContrastLevel: enumThemeContrastLevels read Get_ContrastLevel write Set_ContrastLevel;
  end;

// *********************************************************************//
// DispIntf:  IThemeSizeDisp
// Flags:     (4544) Dual NonExtensible OleAutomation Dispatchable
// GUID:      {72DD2E7F-21E5-46DC-8847-CDDCF58B6725}
// *********************************************************************//
  IThemeSizeDisp = dispinterface
    ['{72DD2E7F-21E5-46DC-8847-CDDCF58B6725}']
    property DisplayName: WideString dispid 500;
    property Name: WideString dispid 501;
    property SystemMetricColor[nSysColorIndex: SYSINT]: LongWord dispid 502;
    property SystemMetricSize[nSystemMetricIndex: enumSystemMetricSize]: SYSINT dispid 503;
    property WebviewCSS: WideString readonly dispid 504;
    property ContrastLevel: enumThemeContrastLevels dispid 505;
    procedure GetSystemMetricFont(nFontIndex: enumSystemMetricFont;
                                  var pLogFontW: {??LOGFONTW} OleVariant); dispid 550;
    procedure PutSystemMetricFont(nFontIndex: enumSystemMetricFont;
                                  var pLogFontW: {??LOGFONTW} OleVariant); dispid 551;
  end;

// *********************************************************************//
// Interface: IThemeManager
// Flags:     (4544) Dual NonExtensible OleAutomation Dispatchable
// GUID:      {04D5D56C-EEAF-4419-B786-300284D6BB5F}
// *********************************************************************//
  IThemeManager = interface(IDispatch)
    ['{04D5D56C-EEAF-4419-B786-300284D6BB5F}']
    function  Get_length: Integer; safecall;
    function  Get_item(varIndex: OleVariant): ITheme; safecall;
    function  Get_schemeLength: Integer; safecall;
    function  Get_schemeItem(varIndex: OleVariant): IThemeScheme; safecall;
    function  Get_WebviewCSS: WideString; safecall;
    function  Get_SelectedTheme: ITheme; safecall;
    procedure Set_SelectedTheme(const ppTheme: ITheme); safecall;
    function  Get_SelectedScheme: IThemeScheme; safecall;
    procedure Set_SelectedScheme(const ppThemeScheme: IThemeScheme); safecall;
    function  GetSpecialTheme(const bstrName: WideString): ITheme; safecall;
    procedure SetSpecialTheme(const bstrName: WideString; const pTheme: ITheme); safecall;
    function  GetSpecialScheme(const bstrName: WideString; out ppThemeScheme: IThemeScheme;
                               out ppThemeStyle: IThemeStyle): IThemeSize; safecall;
    procedure SetSpecialScheme(const bstrName: WideString; const pThemeScheme: IThemeScheme;
                               const pThemeStyle: IThemeStyle; const pThemeSize: IThemeSize); safecall;
    function  GetSelectedSchemeProperty(const bstrName: WideString): WideString; safecall;
    procedure ApplyNow; safecall;
    property length: Integer read Get_length;
    property item[varIndex: OleVariant]: ITheme read Get_item;
    property schemeLength: Integer read Get_schemeLength;
    property schemeItem[varIndex: OleVariant]: IThemeScheme read Get_schemeItem;
    property WebviewCSS: WideString read Get_WebviewCSS;
    property SelectedTheme: ITheme read Get_SelectedTheme write Set_SelectedTheme;
    property SelectedScheme: IThemeScheme read Get_SelectedScheme write Set_SelectedScheme;
  end;

// *********************************************************************//
// DispIntf:  IThemeManagerDisp
// Flags:     (4544) Dual NonExtensible OleAutomation Dispatchable
// GUID:      {04D5D56C-EEAF-4419-B786-300284D6BB5F}
// *********************************************************************//
  IThemeManagerDisp = dispinterface
    ['{04D5D56C-EEAF-4419-B786-300284D6BB5F}']
    property length: Integer readonly dispid 101;
    property item[varIndex: OleVariant]: ITheme readonly dispid 102;
    property schemeLength: Integer readonly dispid 105;
    property schemeItem[varIndex: OleVariant]: IThemeScheme readonly dispid 106;
    property WebviewCSS: WideString readonly dispid 104;
    property SelectedTheme: ITheme dispid 100;
    property SelectedScheme: IThemeScheme dispid 103;
    function  GetSpecialTheme(const bstrName: WideString): ITheme; dispid 151;
    procedure SetSpecialTheme(const bstrName: WideString; const pTheme: ITheme); dispid 152;
    function  GetSpecialScheme(const bstrName: WideString; out ppThemeScheme: IThemeScheme;
                               out ppThemeStyle: IThemeStyle): IThemeSize; dispid 153;
    procedure SetSpecialScheme(const bstrName: WideString; const pThemeScheme: IThemeScheme;
                               const pThemeStyle: IThemeStyle; const pThemeSize: IThemeSize); dispid 154;
    function  GetSelectedSchemeProperty(const bstrName: WideString): WideString; dispid 150;
    procedure ApplyNow; dispid 155;
  end;

// *********************************************************************//
// Interface: IThemePreview
// Flags:     (448) Dual NonExtensible OleAutomation
// GUID:      {B63705F2-B2A2-401E-A20D-643E6B554A1D}
// *********************************************************************//
  IThemePreview = interface(IUnknown)
    ['{B63705F2-B2A2-401E-A20D-643E6B554A1D}']
    procedure UpdatePreview(const pPropertyBag: IPropertyBag); safecall;
    procedure CreatePreview(var hwndParent: TGUID; dwFlags: LongWord; dwStyle: LongWord;
                            dwExStyle: LongWord; x: SYSINT; y: SYSINT; nWidth: SYSINT;
                            nHeight: SYSINT; const pPropertyBag: IPropertyBag; dwCtrlID: LongWord); safecall;
  end;

// *********************************************************************//
// DispIntf:  IThemePreviewDisp
// Flags:     (448) Dual NonExtensible OleAutomation
// GUID:      {B63705F2-B2A2-401E-A20D-643E6B554A1D}
// *********************************************************************//
  IThemePreviewDisp = dispinterface
    ['{B63705F2-B2A2-401E-A20D-643E6B554A1D}']
    procedure UpdatePreview(const pPropertyBag: IPropertyBag); dispid 650;
    procedure CreatePreview(var hwndParent: {??TGUID} OleVariant; dwFlags: LongWord;
                            dwStyle: LongWord; dwExStyle: LongWord; x: SYSINT; y: SYSINT;
                            nWidth: SYSINT; nHeight: SYSINT; const pPropertyBag: IPropertyBag;
                            dwCtrlID: LongWord); dispid 651;
  end;

// *********************************************************************//
// Interface: IPropertyBag
// Flags:     (0)
// GUID:      {55272A00-42CB-11CE-8135-00AA004BB851}
// *********************************************************************//
  IPropertyBag = interface(IUnknown)
    ['{55272A00-42CB-11CE-8135-00AA004BB851}']
    function  RemoteRead(pszPropName: PWideChar; out pVar: OleVariant; const pErrorLog: IErrorLog;
                         varType: LongWord; const pUnkObj: IUnknown): HResult; stdcall;
    function  Write(pszPropName: PWideChar; var pVar: OleVariant): HResult; stdcall;
  end;

// *********************************************************************//
// Interface: IErrorLog
// Flags:     (0)
// GUID:      {3127CA40-446E-11CE-8135-00AA004BB851}
// *********************************************************************//
  IErrorLog = interface(IUnknown)
    ['{3127CA40-446E-11CE-8135-00AA004BB851}']
    function  AddError(pszPropName: PWideChar; var pExcepInfo: TGUID): HResult; stdcall;
  end;

implementation

end.
LVL 1
Haggard1Asked:
Who is Participating?
 
Russell LibbySoftware Engineer, Advisory Commented:
Just to help with this conversion process (my delphi code above):

The Problem:

The problem has to do with the way themeui.dll is implemented between XP (sp1) and XP w/sp2. Prior to XP sp2, the AX library exposed all interface information, as can be seen from the auto generated type library info above (Theme_tlb). It also allowed for IDispatch usage against these dual-dispatch interfaces, making it automation compatible. On XP sp2, only a single interface with one method (GetSelectedSchemeProperty) is exposed from the type library information for themeui.dll. Any attempts to use the prior interfaces using late binding (IDispatch) will fail. BUT, the sp2 version does contain the older interfaces, you just need the type info to bind to them.

Solution:

By getting hold of the prior themeui.dll, one can generate/import the type library information (the process varies by language) that shall be used to interface with the new themeui.dll. It should be noted that the early bound interfaces must be used.

An example done in VBA

' For this sample (done in VBA), I first got the old themeui.dll and placed it on my drive.
' I then registered it, then selected Tools | References | then selected the (old) themeui.dll
' library to import the type information. I built the project, then re-registered the current sp2
' library and ran my project.

Private Sub CommandButton1_Click()

    Dim objManager As Theme.ThemeManager
    Dim objTheme As Theme.Theme
    Dim dwThemes, dwTheme As Integer
   
    Set objManager = New Theme.ThemeManager
   
    ' Get the count of themes
    dwThemes = objManager.Length - 1
   
    ' Walk the items looking for the classic style
    For dwTheme = 0 To dwThemes
        ' Get the theme
        Set objTheme = objManager.Item(dwTheme)
        ' Check the theme name
        If (StrComp(objTheme.DisplayName, "Windows Classic", 1) = 0) Then
            ' Set the theme
            objManager.SelectedTheme = objTheme
            ' Apply the theme
            objManager.ApplyNow
            ' Done
            Exit For
        End If
        ' Release the interface
        Set objTheme = Nothing
    Next
       
    Set objManager = Nothing
     
End Sub

Regards,
Russell


0
 
Bob LearnedCommented:
It might be easier to understand what you are trying to accomplish with this code.  There might be other options available in VB.

Bob
0
 
Haggard1Author Commented:
Hi Bob,

I'm trying to choose and apply an XP Desktop theme. Unfortunately this is the only way to do it for Windows XP SP2, it is much easier with XP SP1 but the PC's this will run on are SP2.

This is why I need help converting the code ; )

Thanks...
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
Haggard1Author Commented:
Again Russell,

Thankyou
0
 
Russell LibbySoftware Engineer, Advisory Commented:

Haggard,
VB is not my forte, I only meant to post this so a true VB guy/gal would have ALL the information needed to provide a VB example. The best I could offer was a VBA snippet, and hopefully it was enough for you to get this working.

Russell
0
 
Haggard1Author Commented:
Hi Russell,

When I try to use SelectedTheme = objManager.SelectedTheme.DisplayName to get the current theme I get and error but if for example I do this  
MsgBox(objManager.SelectedTheme.DisplayName) I get a returned string?
0
 
Russell LibbySoftware Engineer, Advisory Commented:
Error numbers and descriptions are always helpful....

But given this:

>  SelectedTheme = objManager.SelectedTheme.DisplayName

What is the data type for SelectedTheme? You are attempting to get a string data type (DisplayName), so is SelectedTheme also a string data type? If this works:

MsgBox(objManager.SelectedTheme.DisplayName)

Then I would be willing to be you have SelectedTheme defined as an object type. Please check your coding again, and if you still have problems then post the entire code.

Russell




Russell
0
 
Haggard1Author Commented:
Hi Russell,

I resolved that problem the reason being if there is a delay between the creation of an instance of theme.thememanager the selectedtheme.displayname is not available.

i.e.

    Dim objManager As Theme.ThemeManager
    Dim SelectedTheme As String
   
    Set objManager = New Theme.ThemeManager

    MsgBox(objMananger.SelectedTheme.DisplayName) 'This line causes the following line to fail
    SelectedTheme = objMananger.SelectedTheme.DisplayName
   
    Set objManager = Nothing



Could you see if you can get this to work with Delphi, I don't know where to start?

Use the ThemePreview function to produce a preview window of the current theme.

Cheers

0
 
Haggard1Author Commented:
Would you like me to open uo another question?
0
 
Russell LibbySoftware Engineer, Advisory Commented:
No, no problem with this q ...

BUT, I am STRAPPED at the moment with work (for the past 14 hours and still going), and I need to finish my job before I can look at this ;-) It may be tomorrow sometime...

My apologies,

Russell
0
 
Haggard1Author Commented:
No that's perfectly fine, thankyou again for your help.
0
 
Russell LibbySoftware Engineer, Advisory Commented:
Haggard,

From what I can tell, it does not appear to be a delay issue, but something related to the interface being returned (though I can tell you, it does not make much sense).

For example (I apologize to the VB people for the Delphi code ;-)

procedure TForm1.Button1Click(Sender: TObject);
var  pvTM:          IThemeManager;
     pvTheme:       ITheme;
     pvUnk:         IUnknown;
     dwThemes:      Integer;
     dwTheme:       Integer;
begin

  // Create instance of theme manager
  if (CoCreateInstance(CLASS_ThemeManager, nil, CLSCTX_ALL, IID_IThemeManager, pvTM) = S_OK) then
  begin

     // This does not work - returns "the parameter is incorrect"
      pvTheme:=pvTM.SelectedTheme;

But the following does work:

  // Create instance of theme manager
  if (CoCreateInstance(CLASS_ThemeManager, nil, CLSCTX_ALL, IID_IThemeManager, pvTM) = S_OK) then
  begin

     // This does work (get IUnknown)
     pvUnk:=pvTM.SelectedTheme;

     // QI for interface
     if (pvUnk.QueryInterface(ITheme, pvTheme) = S_OK) then
     begin
        // Show display name, do whatever with the interface
        ShowMessage(pvTheme.DisplayName);
     end;

Getting the interface as IUnknown then querying for the ITheme interface works, whereas getting the SelectedTheme as ITheme does not. Because none of this is documented by MS$, I can't really give you an explanation...

Anyways, I don't have VB(A) installed at home to give you a translation, but will take a look at it Monday.

Russell


0
 
Haggard1Author Commented:
Hi Russell,

I trust you had a great weekend?

That's very interesting, it would be nice to know what they where thinking when they designed this. Did you manage to get a look at the ThemePreview function I've had a tinker but have not been able to figure out how it works?

0
 
Russell LibbySoftware Engineer, Advisory Commented:
Yes, nice weekend, thank you.

The VB(A) translation of the above code would be as follows:

    Dim objUnk As Object
    Dim objManager As Theme.ThemeManager
    Dim objTheme As Theme.Theme
    Dim dwThemes, dwTheme As Integer
   
    ' Get theme manager interface
    Set objManager = New Theme.ThemeManager
   
    ' Get SelectedTheme as object, then cast object to ITheme
    Set objUnk = objManager.SelectedTheme
    Set objTheme = objUnk
   
    ' Display the theme name
    MsgBox objTheme.DisplayName
           
As to what MS was thinking, I could not say. But they did not document this interface and probably felt at liberty to change it as they desired.

Regarding the ThemePreview; no, I have not had a chance to look at, nor will I have a chance in the short term. Things have gotten a little busy for me, so my recommendation would be to post a question regarding this to see if someone can help. (I have no experience with this, beyond the code provided to access the theme's.)

Regards,
Russell


0
 
Haggard1Author Commented:
Cheers Russell,

Thanks for all your help ; )
0
 
Russell LibbySoftware Engineer, Advisory Commented:

You are very welcome. I am only sorry I could not help further..

Russell
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.