views:

177

answers:

2

I'm trying to implement IInternetZoneManager in .NET with Webbrowser Control but I have no clue what to do.

I couldn't find any managed code example about this implementation. I'm pretty bad about OLE stuff.

Can anyone provide a sample on this? I spend about 2 days with no luck.

A: 

I don't know if this helps, but he appears to be using the interface in a C++ app:

Monitoring Changes in IE Settings

Gunny
I've seen that one but no clue how to convert that code to .NET and implement it to Webbrowser Control. There are some other C++ code samples in the internet but not clear how to use them in .NET world.
dr. evil
+1  A: 

This is what I get when I convert it:

public class Constants
{
    public const int MAX_PATH = 260;
    public const int MAX_ZONE_PATH = 260;
    public const int MAX_ZONE_DESCRIPTION = 200;
}

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
public struct ZONEATTRIBUTES
{
    public uint cbSize;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = Constants.MAX_PATH)]
    public string szDizplayName;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = Constants.MAX_ZONE_DESCRIPTION)]
    public string szDescription;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = Constants.MAX_PATH)]
    public string szIconPath;
    public uint dwTemplateMinLevel;
    public uint dwTemplateRecommended;
    public uint dwTemplateCurrentLevel;
    public uint dwFlags;
}

public enum URLZONEREG
{
    URLZONEREG_DEFAULT = 0,
    URLZONEREG_HKLM,
    URLZONEREG_HKCU
}

[Guid("79eac9ef-baf9-11ce-8c82-00aa004ba90b")]
[ComImport]
public interface IInternetZoneManager
{
    void CopyTemplatePoliciesToZone(uint dwTemplate, uint dwZone, uint dwReserved);
    void CreateZoneEnumerator(ref uint pdwEnum, ref uint pdwCount, uint dwFlags);
    void DestroyZoneEnumerator(uint dwEnum);
    void GetZoneActionPolicy(uint dwZone, uint dwAction, IntPtr pPolicy, uint cbPolicy, 
        URLZONEREG urlZoneReg);
    void GetZoneAt(uint dwEnum, uint dwIndex, ref uint pdwZone);
    void GetZoneAttributes(uint dwZone, ref ZONEATTRIBUTES pZoneAttributes);
    void GetZoneCustomPolicy(uint dwZone, [In] ref Guid guidKey, ref IntPtr ppPolicy,
        ref uint pcbPolicy, URLZONEREG urlZoneReg);
    void LogAction(uint dwAction, [MarshalAs(UnmanagedType.LPWStr)] string pwszUrl, 
        [MarshalAs(UnmanagedType.LPWStr)] string pwszText, uint dwLogFlags);
    void PromptAction(uint dwAction, IntPtr hwndParent, [MarshalAs(UnmanagedType.LPWStr)] string pwszUrl,
        [MarshalAs(UnmanagedType.LPWStr)] string pwszText, uint dwPromptFlags);
    void SetZoneActionPolicy(uint dwZone, uint dwAction, IntPtr pPolicy, uint cbPolicy,
        URLZONEREG urlZoneReg);
    void SetZoneAttributes(uint dwZone, ref ZONEATTRIBUTES pZoneAttributes);
    void SetZoneCustomPolicy(uint dwZone, [In] ref Guid guidKey, IntPtr pPolicy,
        uint pcbPolicy, URLZONEREG urlZoneReg);
}

I've also posted the definition at pinvoke.net:

http://www.pinvoke.net/default.aspx/Interfaces.IInternetZoneManager

Generally, you should look there first for interop definitions (and contribute if it's not there).

casperOne