detect default browser and retrieve a cookie [SOLVED]

detect default browser and retrieve a cookie [SOLVED]

Postby joseluispalma » Sat Jul 19, 2014 3: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.
Last edited by joseluispalma on Mon Jul 21, 2014 2:17 pm, edited 2 times in total.
joseluispalma
 
Posts: 109
Joined: Mon Apr 30, 2012 9:10 am

Re: detect default browser and retrieve a cookie

Postby Antonio Linares » Sat Jul 19, 2014 9: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
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: detect default browser and retrieve a cookie

Postby Antonio Linares » Sat Jul 19, 2014 9:22 pm

regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: detect default browser and retrieve a cookie

Postby joseluispalma » Sun Jul 20, 2014 9: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: Select all  Expand view
BOOL InternetGetCookie(
  _In_     LPCTSTR lpszUrl,
  _In_     LPCTSTR lpszCookieName,
  _Out_    LPTSTR lpszCookieData,
  _Inout_  LPDWORD lpdwSize
);
 
joseluispalma
 
Posts: 109
Joined: Mon Apr 30, 2012 9:10 am

Re: detect default browser and retrieve a cookie [pending]

Postby Antonio Linares » Mon Jul 21, 2014 10:44 am

Please copy this code at the bottom of your main PRG:

Code: Select all  Expand view

#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
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: detect default browser and retrieve a cookie [pending]

Postby joseluispalma » 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
joseluispalma
 
Posts: 109
Joined: Mon Apr 30, 2012 9:10 am

Re: detect default browser and retrieve a cookie [pending]

Postby Antonio Linares » 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
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: detect default browser and retrieve a cookie [pending]

Postby joseluispalma » Mon Jul 21, 2014 11:27 am

Antonio,

Thanks, this is my code:

Code: Select all  Expand view
#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 ) )
joseluispalma
 
Posts: 109
Joined: Mon Apr 30, 2012 9:10 am

Re: detect default browser and retrieve a cookie [pending]

Postby Antonio Linares » 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: Select all  Expand view
#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
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: detect default browser and retrieve a cookie [pending]

Postby joseluispalma » Mon Jul 21, 2014 2:16 pm

Thank you Antonio.

It´s working now fine.
joseluispalma
 
Posts: 109
Joined: Mon Apr 30, 2012 9:10 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 93 guests

cron