Jump to content
Fivewin Brasil

Gerar arquivo em BASE64


kapiaba

Recommended Posts

Gerar arquivo em BASE64 - By Marcio Ferreira. Skype: live:xtsystem

#include "fivewin.ch"
	FUNCTION Main()
	   Local cfilein,cfileout,tag51
	   cfilein  :='C:\TESTE\IMAGEM.PDF.P7S'
   cFileOut :='BASE64.TXT'
	   if !file(cfilein)
      msginfo('Arquivo: '+CRLF+CRLF+cfilein+CRLF+CRLF+;
      'não encontrado...','Atenção' )
      exit
   endif
	   hb_base64encodefile( cfilein , cfileout  )
	   nHandle := fOpen( cfileout )
	   HB_FreadLine( nHandle, @tag51 )
	   fclose( nHandle )
   ferase( nhandle )
	   dbselectarea(ofilexml)
	   oFilexml:AppendLn( ' <imagem>' )
   oFilexml:AppendLn( '   <protocolo>'+strzero(ARQUIVO->protocolo,10)+'</protocolo>' )
   oFilexml:AppendLn( '   <data_protocolo>'+dtoc(ARQUIVO->data_ent)+'</data_protocolo>' )
   oFilexml:AppendLn( '   <base64>'+tag51+'</base64>' )
   oFilexml:AppendLn( ' </imagem>' )
	   // tem que incluir a TIP.LIB
	   /*
   monto um relatorio, gero a imagem pelo pdfcreator gerando um PDF.
   Depois assino este arquivo com um assinador qualquer.
   Ai depois converto em base64
   Márcio Ferreira - Dúvidas, chama-lo Skype. kkkkkkkkkkkkkkkk - num SAY() de nada.
   Skype: live:xtsystem
   */
	RETURN NIL


 

Link to comment
Share on other sites

  • 1 year later...

Boa tarde !

Tentei usar essa rotina para codificar um arquivo PDF em base64 e já na compilação deu o erro: 

Error: Unresolved external '_hb_retc_null' referenced from C:\Empresa\SISTEMAS\LIB\TIP.LIB|base64  

Alguma idéia de como resolver esse erro na compilação ? 

Grata.

Link to comment
Share on other sites

Inclua a função

#pragma BEGINDUMP

#include <hbapi.h>
#include <windows.h>
#include <ShellApi.h>
#include <ShlObj.h>
///#include "hbapi.h"

typedef LONG ( * PDLLREGISTERSERVER ) ( void );


HB_FUNC( HB_BASE64ENCODE )
{
   ULONG len = hb_parclen( 1 );

   if( len <= INT_MAX ) /* TOFIX */
   {
      const char * s = hb_parcx( 1 );
      char * t, * p;

      t = p = ( char * ) hb_xgrab( ( 4 * ( ( len + 2 ) / 3 ) + 1 ) * sizeof( *t ) );

      while( len-- > 0 )
      {
         static const char s_b64chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
         int x, y;

         x = *s++;
         *p++ = s_b64chars[ ( x >> 2 ) & 0x3F ];

         if( len-- <= 0 )
         {
            *p++ = s_b64chars[ ( x << 4 ) & 0x3F ];
            *p++ = '=';
            *p++ = '=';
            break;
         }
         y = *s++;
         *p++ = s_b64chars[ ( ( x << 4 ) | ( ( y >> 4 ) & 0x0F ) ) & 0x3F ];

         if( len-- <= 0 )
         {
            *p++ = s_b64chars[ ( y << 2 ) & 0x3F ];
            *p++ = '=';
            break;
         }
         x = *s++;
         *p++ = s_b64chars[ ( ( y << 2 ) | ( ( x >> 6 ) & 3 ) ) & 0x3F ];
         *p++ = s_b64chars[ x & 0x3F ];
      }
      *p = '\0';

      hb_retc_buffer( t );
   }
   else
      hb_retc_null();
}


#pragma ENDDUMP

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...