Click here to Skip to main content
16,005,236 members
Home / Discussions / C#
   

C#

 
QuestionGame port I/O ? Pin
Christian Graus31-Aug-04 10:58
protectorChristian Graus31-Aug-04 10:58 
AnswerRe: Game port I/O ? Pin
Heath Stewart31-Aug-04 12:15
protectorHeath Stewart31-Aug-04 12:15 
GeneralRe: Game port I/O ? Pin
Christian Graus1-Sep-04 10:49
protectorChristian Graus1-Sep-04 10:49 
AnswerRe: Game port I/O ? Pin
mav.northwind1-Sep-04 4:55
mav.northwind1-Sep-04 4:55 
GeneralListView Pin
elena1234531-Aug-04 10:57
elena1234531-Aug-04 10:57 
GeneralRe: ListView Pin
Heath Stewart31-Aug-04 12:28
protectorHeath Stewart31-Aug-04 12:28 
GeneralMicrosoft Web Browser Control Cookies Pin
kayhustle31-Aug-04 10:47
kayhustle31-Aug-04 10:47 
GeneralRe: Microsoft Web Browser Control Cookies Pin
Heath Stewart31-Aug-04 12:11
protectorHeath Stewart31-Aug-04 12:11 
You need to P/Invoke InternetGetCookie:
[DllImport("wininet.dll", CharSet=CharSet.Auto, SetLastError=true)]
static extern bool InternetGetCookie(string url, string name, [Out] string data,
  ref int size);
Do not declare the third param using out, be sure to use the OutAttribute as I've done above. A String (C# alias string) is already a reference type, so you're already passing the address of a string variable. Double referencing will crash the CLR.

To call it, consider a wrapper method since P/Invoke methods should not generally be exposed as public members (depending on if you're writing a library or just using this in an app):
public string GetCookie(string url, string name)
{
  int size = 0;
  string data = null;
  // Get the size for 'data' first.
  if (!InternetGetCookie(url, name, null, ref size))
  {
    if (Marshal.GetLastWin32Error() == 122) // ERROR_INSUFFICIENT_BUFFER
    {
      data = new string('\0', size);
      if (InternetGetCookie(url, name, data, ref size))
        return data.Trim();
    }
  }
  return null;
}
You'll still need to parse the cookie string, though, but that should be simple.

This posting is provided "AS IS" with no warranties, and confers no rights.

Software Design Engineer
Developer Division Sustained Engineering
Microsoft

[My Articles]
GeneralRe: Microsoft Web Browser Control Cookies Pin
kayhustle31-Aug-04 15:51
kayhustle31-Aug-04 15:51 
GeneralRe: Microsoft Web Browser Control Cookies Pin
Heath Stewart1-Sep-04 9:37
protectorHeath Stewart1-Sep-04 9:37 
Generalrectangle select Pin
hudhud31-Aug-04 10:15
hudhud31-Aug-04 10:15 
GeneralRe: rectangle select Pin
Christian Graus31-Aug-04 11:02
protectorChristian Graus31-Aug-04 11:02 
GeneralRe: rectangle select Pin
hudhud1-Sep-04 19:54
hudhud1-Sep-04 19:54 
GeneralRe: rectangle select Pin
Christian Graus2-Sep-04 10:13
protectorChristian Graus2-Sep-04 10:13 
QuestionHow to databind a CheckedListBox control Pin
abhishk2001@yahoo.com31-Aug-04 9:52
abhishk2001@yahoo.com31-Aug-04 9:52 
AnswerRe: How to databind a CheckedListBox control Pin
Heath Stewart31-Aug-04 12:03
protectorHeath Stewart31-Aug-04 12:03 
GeneralDrag and drop between two treeview Pin
teomanx31-Aug-04 9:21
teomanx31-Aug-04 9:21 
GeneralRe: Drag and drop between two treeview Pin
Heath Stewart31-Aug-04 11:49
protectorHeath Stewart31-Aug-04 11:49 
General"see" tag not rendered Pin
Gary Hyslop at home31-Aug-04 9:09
Gary Hyslop at home31-Aug-04 9:09 
GeneralRe: "see" tag not rendered Pin
Heath Stewart31-Aug-04 11:32
protectorHeath Stewart31-Aug-04 11:32 
GeneralNested Tree Nodes At Run Time Pin
MohamedShehab31-Aug-04 8:17
MohamedShehab31-Aug-04 8:17 
GeneralRe: Nested Tree Nodes At Run Time Pin
LongRange.Shooter1-Sep-04 8:08
LongRange.Shooter1-Sep-04 8:08 
GeneralMailMessage headers Pin
simrang31-Aug-04 6:55
simrang31-Aug-04 6:55 
GeneralRe: MailMessage headers Pin
Heath Stewart31-Aug-04 7:14
protectorHeath Stewart31-Aug-04 7:14 
GeneralRe: MailMessage headers Pin
simrang31-Aug-04 10:47
simrang31-Aug-04 10:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.