FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour detect default browser and retrieve a cookie [SOLVED]
Posts: 109
Joined: Mon Apr 30, 2012 09:10 AM
detect default browser and retrieve a cookie [SOLVED]
Posted: Sat Jul 19, 2014 03:34 PM

Hello,

I would like to make two questions please.

1) How can I detect the default Internet browser on the PC?.

2) How can I read a cookie?.

Thank you in advance.

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: detect default browser and retrieve a cookie
Posted: Sat Jul 19, 2014 09:22 PM
Jose Luis,

http://support.microsoft.com/kb/299853

De manera predeterminada, Windows XP utiliza una configuraci贸n global en la clave del registro HKeyLocalMachine (HKLM) para establecer una inicial, el correo electr贸nico predeterminado y el cliente de explorador Web en el men煤 Inicio . Windows XP tambi茅n implementa nuevas claves del registro en HKeyCurrentUser (HKCU) para almacenar individuales de internet y la informaci贸n de cliente de correo electr贸nico de cada usuario como parte de su perfil, si los usuarios seleccionan a un cliente diferente a la predeterminada
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: detect default browser and retrieve a cookie
Posted: Sat Jul 19, 2014 09:22 PM
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 109
Joined: Mon Apr 30, 2012 09:10 AM
Re: detect default browser and retrieve a cookie
Posted: Sun Jul 20, 2014 09:46 AM
Antonio,

Many thanks!.

I don麓t know C. Can you please indicate me how can I call this C function from Fivewin?:

Code (fw): Select all Collapse
BOOL InternetGetCookie(
  _In_     LPCTSTR lpszUrl,
  _In_     LPCTSTR lpszCookieName,
  _Out_    LPTSTR lpszCookieData,
  _Inout_  LPDWORD lpdwSize
);
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: detect default browser and retrieve a cookie [pending]
Posted: Mon Jul 21, 2014 10:44 AM
Please copy this code at the bottom of your main PRG:

Code (fw): Select all Collapse
#pragma BEGINDUMP

#include <windows.h>
#include <hbapi.h>

HB_FUNC( INTERNETGETCOOKIE )
{
   DWORD dwSize = 0;      
   char * buffer;

   InternetGetCookie( ( LPCTSTR ) hb_parc( 1 ), ( LPCTSTR ) hb_parc( 2 ), ( LPCTSTR ) hb_parc( 3 ), NULL, &dwSize );

   buffer = ( char * ) hb_xgrab( dwSize );

   if( InternetGetCookie( ( LPCTSTR ) hb_parc( 1 ), ( LPCTSTR ) hb_parc( 2 ), ( LPCTSTR ) hb_parc( 3 ), buffer, &dwSize ) )
      hb_retclen( buffer, dwSize );
   else
      hb_retc( "" );

   hb_xfree( buffer );
);

#pragma ENDDUMP
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 109
Joined: Mon Apr 30, 2012 09:10 AM
Re: detect default browser and retrieve a cookie [pending]
Posted: Mon Jul 21, 2014 10:54 AM

Antonio,

Many thanks, but I get this errors:

Borland C++ 5.82 for Win32 Copyright (c) 1993, 2005 Borland
antonio.c:
Warning W8065 antonio.prg 50: Call to function 'InternetGetCookie' with no prototype in function HB_FUN_INTERNETGETCOOKIE
Warning W8065 antonio.prg 54: Call to function 'InternetGetCookie' with no prototype in function HB_FUN_INTERNETGETCOOKIE
Turbo Incremental Link 5.69 Copyright (c) 1997-2005 Borland
Error: Unresolved external '_InternetGetCookie' referenced from C:\API\COOKIES\ANTONIO.OBJ

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: detect default browser and retrieve a cookie [pending]
Posted: Mon Jul 21, 2014 11:06 AM

Jose Luis,

This header file is missing:

include <wininet.h>

and you also have to link wininet.lib

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 109
Joined: Mon Apr 30, 2012 09:10 AM
Re: detect default browser and retrieve a cookie [pending]
Posted: Mon Jul 21, 2014 11:27 AM
Antonio,

Thanks, this is my code:

Code (fw): Select all Collapse
#pragma BEGINDUMP

#include <windows.h>
#include <wininet.h>
#include <hbapi.h>

/*
BOOLAPI
InternetGetCookie(
聽 聽 __in LPCSTR lpszUrl,
聽 聽 __in_opt LPCSTR lpszCookieName,
聽 聽 __out_ecount_opt(*lpdwSize) LPSTR lpszCookieData,
聽 聽 __inout LPDWORD lpdwSize
聽 聽 );
*/


HB_FUNC( INTERNETGETCOOKIE )

{
聽 聽DWORD dwSize = 0;
聽 聽char * buffer;

聽 聽InternetGetCookie( ( LPCTSTR ) hb_parc( 1 ), ( LPCTSTR ) hb_parc( 2 ), NULL, &dwSize );

聽 聽buffer = ( char * ) hb_xgrab( dwSize );



聽 聽if( InternetGetCookie( ( LPCTSTR ) hb_parc( 1 ), ( LPCTSTR ) hb_parc( 2 ), buffer, 聽&dwSize ) )
聽 聽 聽 hb_retclen( buffer, dwSize );
聽 聽else
聽 聽 聽 hb_retc( "" );

聽 聽hb_xfree( buffer );
}


#pragma ENDDUMP



But in your calls you put an extra parameter that gives error:

InternetGetCookie( ( LPCTSTR ) hb_parc( 1 ), ( LPCTSTR ) hb_parc( 2 ), ( LPCTSTR ) hb_parc( 3 ), NULL, &dwSize );

if( InternetGetCookie( ( LPCTSTR ) hb_parc( 1 ), ( LPCTSTR ) hb_parc( 2 ), ( LPCTSTR ) hb_parc( 3 ), buffer, &dwSize ) )
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: detect default browser and retrieve a cookie [pending]
Posted: Mon Jul 21, 2014 12:47 PM
Jose Luis,

Yes, you are right. My mistake. I did not test the code, just wrote it here directly on my post.

This would be the right version:

Code (fw): Select all Collapse
#pragma BEGINDUMP

#include <windows.h>
#include <wininet.h>
#include <hbapi.h>

HB_FUNC( INTERNETGETCOOKIE )
{
聽 聽DWORD dwSize = 0; 聽 聽 聽
聽 聽char * buffer;

聽 聽InternetGetCookie( ( LPCTSTR ) hb_parc( 1 ), ( LPCTSTR ) hb_parc( 2 ), NULL, &dwSize );

聽 聽buffer = ( char * ) hb_xgrab( dwSize );

聽 聽if( InternetGetCookie( ( LPCTSTR ) hb_parc( 1 ), ( LPCTSTR ) hb_parc( 2 ), buffer, &dwSize ) )
聽 聽 聽 hb_retclen( buffer, dwSize );
聽 聽else
聽 聽 聽 hb_retc( "" );

聽 聽hb_xfree( buffer );
);

#pragma ENDDUMP
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 109
Joined: Mon Apr 30, 2012 09:10 AM
Re: detect default browser and retrieve a cookie [pending]
Posted: Mon Jul 21, 2014 02:16 PM

Thank you Antonio.

It麓s working now fine.

Continue the discussion