gpt4 book ai didi

c# - 如何在 C# 中使用 UrlMon.dll 中的 CreateUri 方法

转载 作者:行者123 更新时间:2023-11-28 06:34:58 26 4
gpt4 key购买 nike

我需要使用 CreateUri来自 C# 中 UrlMon.dll (...\Windows\System32) 的方法,但我不能,因为最后一个参数是 IUri,它也在 UriMon.dll 中,我不知道如何使用它。

我无法将此 dll 添加为引用或使用 Assembly.GetType() 获取 IUri 类型。

有什么想法吗?

最佳答案

我找到了解决方案:

public enum UriProperty
{
ABSOLUTE_URI = 0,
STRING_START = ABSOLUTE_URI,
AUTHORITY = 1,
DISPLAY_URI = 2,
DOMAIN = 3,
EXTENSION = 4,
FRAGMENT = 5,
HOST = 6,
PASSWORD = 7,
PATH = 8,
PATH_AND_QUERY = 9,
QUERY = 10,
RAW_URI = 11,
SCHEME_NAME = 12,
USER_INFO = 13,
USER_NAME = 14,
STRING_LAST = USER_NAME,
HOST_TYPE = 15,
DWORD_START = HOST_TYPE,
PORT = 16,
SCHEME = 17,
ZONE = 18,
DWORD_LAST = ZONE
}

[ComImport]
[Guid("A39EE748-6A27-4817-A6F2-13914BEF5890"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IUri
{
UInt32 GetPropertyBSTR([In]UriProperty uriProp, [Out]out string strProperty, [In]UInt32 dwFlags);
UInt32 GetPropertyLength([In]UriProperty uriProp, [Out] out UInt32 pcPropLen, [In]UInt32 dwFlags);
UInt32 GetPropertyDWORD([In]UriProperty uriProp, [Out] out UInt32 pcPropValue, [In]UInt32 dwFlags);
UInt32 HasProperty([In]UriProperty uriProp, [Out] out bool fHasProperty);
UInt32 GetAbsoluteUri([MarshalAs(UnmanagedType.BStr)][Out] out string sAbsoluteUri);
UInt32 GetAuthority([MarshalAs(UnmanagedType.BStr)][Out] out string sAuthority);
UInt32 GetDisplayUri([MarshalAs(UnmanagedType.BStr)][Out] out string sDisplayString);
UInt32 GetDomain([MarshalAs(UnmanagedType.BStr)][Out] out string sDomain);
UInt32 GetExtension([MarshalAs(UnmanagedType.BStr)][Out] out string sExtension);
UInt32 GetFragment([MarshalAs(UnmanagedType.BStr)][Out] out string sFragment);
UInt32 GetHost([MarshalAs(UnmanagedType.BStr)][Out] out string sHost);
UInt32 GetPassword([MarshalAs(UnmanagedType.BStr)][Out] out string sPassword);
UInt32 GetPath([MarshalAs(UnmanagedType.BStr)][Out] out string sPath);
UInt32 GetPathAndQuery([MarshalAs(UnmanagedType.BStr)][Out] out string sPathAndQuery);
UInt32 GetQuery([MarshalAs(UnmanagedType.BStr)][Out] out string sQuery);
UInt32 GetRawUri([MarshalAs(UnmanagedType.BStr)][Out] out string sRawUri);
UInt32 GetSchemeName([MarshalAs(UnmanagedType.BStr)][Out] out string sSchemeName);
UInt32 GetUserInfo([MarshalAs(UnmanagedType.BStr)][Out] out string sUserInfo);
UInt32 GetUserName([MarshalAs(UnmanagedType.BStr)][Out] out string sUserName);
UInt32 GetHostType([Out] uint dwHostType);
UInt32 GetPort([Out] uint dwPort);
UInt32 GetScheme([Out] uint dwScheme);
UInt32 GetZone([Out] uint dwZone);
UInt32 GetProperties([Out] uint dwFlags);
UInt32 IsEqual([In]IUri pUri,[Out] bool fEqual);
}

这给了我们 IUri 接口(interface),现在我们可以使用 CreateUri 方法:

[DllImport("UrlMon.dll", SetLastError = true)]
public static extern bool CreateUri(string uri, uint flag, IntPtr dwReserved, out IUri a);

关于c# - 如何在 C# 中使用 UrlMon.dll 中的 CreateUri 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26921151/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com