Re: How to print the cookie value

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



bhattacharjeesoft@xxxxxxxxx wrote:
I have not used InternetGetCookie, but it would seems that you may be
mixing char and wchar_t strings.

Try like this:

LPCTSTR name= _T("usrauth");
TCHAR buffer [16384];
DWORD bufferSize = sizeof(buffer)/sizeof(buffer[0]);
BOOL bRes = InternetGetCookie((_T("http://www.mirracle.com";), name,
buffer, &bufferSize);
::MessageBox(NULL, buffer, NULL, MB_OK);

This should work for both Unicode and ANSI builds.

--
David Wilkinson
Visual C++ MVP

'InternetGetCookieW' : cannot convert parameter 1 from 'unsigned short
[26]' to 'const char *'

that is the error I am getting if I use ur code.Function is returning
false with error code 12006.What to do?

bhattacharjeesoft:

Are you sure you used the code exactly as I (and Giovanni) suggested?
Actually, there was a typo in my version (unmatched parenthesis), but you must have fixed that. Should be

BOOL bRes = InternetGetCookie(_T("http://www.mirracle.com";), name,
buffer, &bufferSize);

What version of Visual Studio are you using? If you are using VC6, have you defined both UNICODE and _UNICODE (or neither)? If you are using VC7 or later, I would also suggest you select the "treat wchar_t as a distinct type" (or something like this) in the project settings.

But, your error message does not seem consistent with the documentation on InternetGetCookie(). Surely InternetGetCookieW() should take a LPCWSTR as first parameter?

--
David Wilkinson
Visual C++ MVP
.



Relevant Pages

  • Re: NFS Character Issues on Suse 9.1
    ... A buffer is a thing measured in bytes, ... unicode, ... It's still slower for western alphabets, ... and one "feature" version that contains the newest software. ...
    (alt.os.linux.suse)
  • Re: Help reading registry key
    ... Your buffer should be coming back with the same trash that was in ... It will write a UNICODE ... > I'll assume you know about enumering a registry key so I won't detail ... > DWORD nNameSize = nMaxKeyNameSize; ...
    (microsoft.public.pocketpc.developer)
  • Re: CString to LPCSTR
    ... The proper thing to do depends on what format of text the RichEdit control ... Since you're apparently building the project with UNICODE ... by the minimum size of the byte buffer, or the length of the string. ...
    (microsoft.public.vc.mfc)
  • Re: CEditView & UNICODE problems
    ... When the buffer is being written to disk, ... >first character as the terminating null. ... Make your application Unicode. ... Don't use the V6 controls (remove the common controls manifest from ...
    (microsoft.public.vc.mfc)