Why does IEGetProtectedModeCookie () always return 0x80070057?

According to the function description in http://msdn.microsoft.com/en-us/library/cc196998%28v=VS.85%29.aspx , I wrote the following code to try to get IE protected cookies:

public static string GetProtectedModeCookie(string lpszURL, string lpszCookieName, uint dwFlags)
{
    var size = 255;
    var sb = new System.Text.StringBuilder(size);
    var acturalSize = sb.Capacity;
    var code = IEGetProtectedModeCookie(lpszURL, lpszCookieName, sb, ref acturalSize, dwFlags);
    if ((code & 0x80000000) > 0) return string.Empty;
    if (acturalSize > size)
    {
        sb.EnsureCapacity(acturalSize);
        IEGetProtectedModeCookie(lpszURL, lpszCookieName, sb, ref acturalSize, dwFlags);
    }
    return sb.ToString();
}

[DllImport("ieframe.dll", SetLastError = true)]
public static extern uint IEGetProtectedModeCookie(string lpszURL, string lpszCookieName, System.Text.StringBuilder pszCookieData, ref int pcchCookieData, int dwFlags);

to check this function:

var cookies = GetProtectedModeCookie("http://bbs.pcbeta.com/", null, 0);

But the api IEGetProtectedModeCookie always returns 0x80070057 , which indicates that one or more of the arguments is invalid. I was confused after many attempts to finally fail to get this result. Can anybody help me?

+3
source share
2 answers

IEGetProtectedModeCookie E_INVALIDARG, , URL- . IEIsProtectedModeURL API. , URL - , . API InternetGetCookie E_INVALIDARG, URL- .

, API IEGetProtectedModeCookie (, Admin); ERROR_INVALID_ACCESS (0x8000000C).

, :

[DllImport("ieframe.dll", CharSet = CharSet.Unicode, EntryPoint = "IEGetProtectedModeCookie", SetLastError = true)]
public static extern int IEGetProtectedModeCookie(String url, String cookieName, StringBuilder cookieData, ref int size, uint flag);


private void GetCookie_Click(object sender, EventArgs e)
{
    int iSize = 4096;
    StringBuilder sbValue = new StringBuilder(iSize);

    int hResult = IEAPI.IEGetProtectedModeCookie("http://www.google.com", "PREF", sbValue, ref iSize, 0);

    if (hResult == 0)
    {
        MessageBox.Show(sbValue.ToString());
    }
    else
    {
        MessageBox.Show("Failed to get cookie. HRESULT=0x" + hResult.ToString("x") + "\nLast Win32Error=" + Marshal.GetLastWin32Error().ToString(), "Failed");
    }
}
+5

Charset DllImport. API, , :

[DllImport("ieframe.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern uint IEGetProtectedModeCookie(string lpszURL, string lpszCookieName, System.Text.StringBuilder pszCookieData, ref int pcchCookieData, uint dwFlags);

Charset , API 0x80070057, , .

+1

All Articles