Problemas con TMail y FWH 9.04

Problemas con TMail y FWH 9.04

Postby Carlos Mora » Mon Jul 26, 2010 10:28 am

Buenos días gente,

Estoy actualizando un programa que está compilado con FWH 7.07 a la última versión que tengo de FWH, 9.04.
Al recompilar todo funciona bien excepto las rutinas donde uso la TMail.
Primero, las copias de seguridad que hace el prg (en un fichero zip) se envían por mail, usando el siguiente código:
Code: Select all  Expand view

            If lCorreo .And. lOk
               #include "Mail.ch"
               If cEsOutLook == 'NO'
                  DEFINE MAIL oMail ;
                                SUBJECT 'Copia de Seguridad de Contabilidad - '+cNombre ;
                                TEXT 'Generado por AtiConta 2.0 el '+DtoC(Date())+' a las '+Left( Time(), 5 ) ;
                                FILES ( cFichero ), ( cFichero ) ;
                                ORIGIN AllTrim( cMailUser ), AllTrim( cMailUser ) ;
                                TO 'Destino del correo', ( AllTrim( cCorreo ) );
                                // FROM USER
               Else
                  DEFINE MAIL oMail ;
                                SUBJECT 'Copia de Seguridad de Contabilidad - '+cNombre ;
                                TEXT 'Generado por AtiConta 2.0 el '+DtoC(Date())+' a las '+Left( Time(), 5 ) ;
                                FILES ( cFichero ), ( cFichero ) ;
                                ORIGIN AllTrim( cMailUser ), AllTrim( cMailUser ) ;
                                TO ( AllTrim( cCorreo ) );
                                // FROM USER
               EndIf
               SEND MAIL oMail

               MsgInfo( 'Se ha enviado el correo!' )

            EndIf
 


este código funciona perfectamente en 7.07, pero en la versión recompilada con 9.04 nunca alcanza la línea del MsgInfo(). Lo extraño es que en la clase TMail añadí msginfos en el método Activate, y aparentemente sale del método, pero nunca retorna a la funcion. El correo se envía y llega, pero la aplicacion se queda clavada, en la lista de procesos aparece ocupando entre un 10 y un 15% del procesador, y la unica solucion es matar el proceso.

Code: Select all  Expand view

METHOD Activate() CLASS TMail

   local cCurPath

   // ::nRetCode = MAPILogOn()

   if ::nRetCode != -1
      cCurPath = CurDrive() + ":\" + CurDir()

      MsgInfo( cCurPath +' antes' )
      ::nRetCode = MAPISendMail( ::cSubject, ::cNoteText, ::cMsgType,;
                   DToS( ::dDate ) + "
" + ::cTime,;
                   ::cConversationID, ::lReceipt, ::lFromUser,;
                   ::aOrigin, ::aRecipients, ::aFiles )
      MsgInfo( 'Resultado: '+LTrim(Str( ::nRetCode ) )  )
      lChDir( cCurPath )
      MsgInfo( cCurPath +' chdir' )

   else
      MsgStop( "
Error initializing mail" )
   endif

return nil



Otro punto donde me produce fallo es en una funcion que añadí a mi preview para generar un pdf y enviarlo por correo. En la preview.prg añadí :

Code: Select all  Expand view

function UserMail(afiles)
   local oMail
   DEFINE MAIL oMail ;
      FROM USER ;
      SUBJECT "Envio de documento" ;
      TEXT "" ;
      RECEIPT
      omail:afiles:=afiles
   ACTIVATE MAIL oMail
return nil
 


Y en este caso el programa casca pero Windows me da un msg de error diciendome que :
"El programa dejó de funcionar correctamente por un problema. Windows cerrará el programa y le informará si encuentra alguna solución"

Pero siempre ocurre despues de llamar a SEND MAIL oMail.

he comparado el codigo fuente de TMail.prg y mapi.c de ambas versiones de FWH (7.07 y 9.04) y no hay diferencias.

¿Alguien me puede ayudar? ¿Les ocurre algo parecido? No se por donde seguir con este tema. Y tiene que ser con MAPI, porque así no hay problemas de configuración de cuentas, y los correos enviados quedan en el directorio de correos enviados en el cliente de correos por defecto.
Saludos
Carlos Mora
http://harbouradvisor.blogspot.com/
StackOverflow http://stackoverflow.com/users/549761/carlos-mora
“If you think education is expensive, try ignorance"
Carlos Mora
 
Posts: 988
Joined: Thu Nov 24, 2005 3:01 pm
Location: Madrid, España

Re: Problemas con TMail y FWH 9.04

Postby cyberkily » Fri Sep 24, 2010 11:41 am

Buenas Carlos,

Me pasa exactamente lo mismo que a tí, con fw envío mails sin ningún problema, pero con FWh 9.11 se me queda muerto el programa en cuanto se abre el outlook. Incluso con el sample "testmail.prg" sucede lo mismo....

Espero nos podáis ayudar.

Gracias.
Roberto Sánchez k:
cyberkily
 
Posts: 24
Joined: Fri Dec 05, 2008 11:20 pm

Re: Problemas con TMail y FWH 9.04

Postby mgsoft » Fri Sep 24, 2010 12:01 pm

Hola

A mi también me sucede lo mismo. Hay un bug en el código c como consecuencia de los cambios de Harbour 2.x y la redenominación de hb_parnv, etc, pero no he dado con él.

saludos
Saludos,

Eduardo
User avatar
mgsoft
 
Posts: 422
Joined: Mon Aug 17, 2009 12:18 pm
Location: España

Re: Problemas con TMail y FWH 9.04

Postby Carlos Mora » Sun Sep 26, 2010 3:43 pm

Gracias amigos por confirmar el problema, me imaginaba que el problema estaba en algún cambio en el código C, pero lamentablemente ese error no es evidente, ya que el programa enlaza sin inconvenientes.

Antonio, podrías echarnos una mano con este tema?
Saludos
Carlos Mora
http://harbouradvisor.blogspot.com/
StackOverflow http://stackoverflow.com/users/549761/carlos-mora
“If you think education is expensive, try ignorance"
Carlos Mora
 
Posts: 988
Joined: Thu Nov 24, 2005 3:01 pm
Location: Madrid, España

Re: Problemas con TMail y FWH 9.04

Postby Carlos Mora » Wed Sep 29, 2010 1:42 pm

Bueno, retomando el tema, he usado para hacer pruebas el testmail.prg del directorio Samples, y he usado la última versión de FW que tenemos, la 9.05.

Dicho prg ha sido corregido para que los archivos a los que hace referencia existan, y ha sido compilado con Harbour y xHarbour.

Usando xHarbour el programa funciona correctamente! Pero usando Harbour, la opcion de envío del correo desatendida con archivo adjunto se queda colgado.
Code: Select all  Expand view

// FiveWin - Windows MAPI (mail services) support demonstration

#include "FiveWin.ch"
#include "Mail.ch"

static oWnd

//----------------------------------------------------------------------------//

function Main()

   local oBar

   DEFINE WINDOW oWnd TITLE "Using Windows MAIL Services"

   DEFINE BUTTONBAR oBar _3D SIZE 33, 33 OF oWnd

   DEFINE BUTTON OF oBar ACTION MsgInfo( MAPILogOn() ) ;
      MESSAGE "LogOn in the mail system" TOOLTIP "LogOn"

   DEFINE BUTTON OF oBar ;
      ACTION ( MAPILogOff(), MsgInfo( "MAIL LogOff done!" ) ) ;
      MESSAGE "LogOff from the mail system" TOOLTIP "LogOff"

   DEFINE BUTTON OF oBar GROUP ;
      ACTION InteractiveMessage() ;
      MESSAGE "Send an interactive message" TOOLTIP "Interactive"

   DEFINE BUTTON OF oBar ;
      ACTION DirectMessage();
      MESSAGE "Send a direct message" TOOLTIP "Direct"

   DEFINE BUTTON OF oBar GROUP ACTION oWnd:End() TOOLTIP "End"

   SET MESSAGE OF oWnd TO "FiveWin - Windows MAIL support" CENTERED

   ACTIVATE WINDOW oWnd ;
      VALID MsgYesNo( "Want to end ?" )

return nil

//----------------------------------------------------------------------------//

function InteractiveMessage()

   local oMail

   DEFINE MAIL oMail ;
      SUBJECT "Testing..." ;
      TEXT "This is real xBase power at your fingertips!" ;
      FROM USER ;
      RECEIPT

   ACTIVATE MAIL oMail

   MsgInfo( oMail:nRetCode )

return nil

//----------------------------------------------------------------------------//

function DirectMessage()

   local oMail

   DEFINE MAIL oMail ;
      SUBJECT "FiveWin Mail-control power" ;
      TEXT    "This is real xBase power at your fingertips!" ;
      FILES   'C:\Proyectos\TestImap\Source\TestImap.prg', 'C:\Proyectos\TestImap\Source\TestImap.prg' ;
      TO      "Carlos", "carlos.mora@atisa.es"

   ACTIVATE MAIL oMail
   // Esta línea nunca llega a ejecutarse.
   MsgInfo( oMail:nRetCode )

return nil

//----------------------------------------------------------------------------//
 


he probado esto en varios equipos y en todos sucede lo mismo.
Antonio, podrías echarme una mano con esto?

Gracias
Saludos
Carlos Mora
http://harbouradvisor.blogspot.com/
StackOverflow http://stackoverflow.com/users/549761/carlos-mora
“If you think education is expensive, try ignorance"
Carlos Mora
 
Posts: 988
Joined: Thu Nov 24, 2005 3:01 pm
Location: Madrid, España

Re: Problemas con TMail y FWH 9.04

Postby Carlos Mora » Wed Sep 29, 2010 2:19 pm

Mas información!
en lugar de usar el harbour que viene con FWH usé uno que bajé de harbour-project.org. EL programa, al quedarse congelado, genera un log de texto que dice:

Code: Select all  Expand view

Application Internal Error - C:\FWH905\samples\testmail.exe
Terminated at: 2010.09.29 16:16:23
Unrecoverable error 6005: Exception error:

    Exception Code:C0000005
    Exception Address:004672DC
    EAX:003AFBE8  EBX:0056337C  ECX:00000001  EDX:003AF868
    ESI:004BC98F  EDI:00512BB6  EBP:0012F1C4
    CS:EIP:001B:004672DC  SS:ESP:0023:0012F0C4
    DS:0023  ES:0023  FS:003B  GS:0000
    Flags:00010246
    CS:EIP: F6 41 10 80 75 20 8B 03 8B 50 FC 8B 03 F6 42 10
    SS:ESP: 004BC9DA 00000000 004BC448 016F6318 00000080 0012F0EC 00462B08 016F62A0 016F6308 016F62F8 0012F100 004633C0 016F62F8 0056338C 003B4AA0 0012F10C

    C stack:
    EIP:     EBP:       Frame: OldEBP, RetAddr, Params...
    004672DC 0012F1C4   0012F1D4 00406225 00512AFF 00512480
    00406225 0012F1D4   0012F1F4 0046B819 0056337C 00000043 00000000 003B9920 0025000D 00000063
    0046B819 0012F1F4   0012F300 00465D38 00000000 004BC759 00000000 004BC408 35301575 0012F234 7652712F 76527117
    00465D38 0012F300   0012F32C 004011A8 004BC906 004BC368 0046B779 0056337C 00000040 00000000 003B9920 00000000
    004011A8 0012F32C   0012F438 00465C7E 00000000 0056337C FFFFFFFF 003B4488 004BB77E 00000215 00000024 00000001
    00465C7E 0012F438   0012F448 0045BC72 004BC756 004BC368
    0045BC72 0012F448   0012F47C 0046B97C 003B4488 00534757 00000000 00532354 0046B819 0056337C 0000003E 00000000
    0046B97C 0012F47C   0012F588 00465D38 00000001 00534CD6 00000000 00532924 00000000 00000070 FFFFFFFF FFFFFFFF
    00465D38 0012F588   0012F598 00407C44 005346F4 00532054
    00407C44 0012F598   0012F5B8 0046B819 0056337C 00000037 00000000 003C8148 01C9000A 000001BB
    0046B819 0012F5B8   0012F6C4 00465D38 00000000 00000000 00000202 004C3444 00000078 0012F5E8 00462B08 01703DF8
    00465D38 0012F6C4   0012F6D4 00407D04 00534B08 00532054
    00407D04 0012F6D4   0012F6F4 0046B70C 00160010 00000032 00000000 003C8148 0104000A 00000275
    0046B70C 0012F6F4   0012F700 0046BAE9 003A0003
    0046BAE9 0012F700   0012F728 0040D0ED 00000003 004CD9A2 00000000 004CA2B0 0002337C 0012F748 0046B7DA 003B3DF8
    0040D0ED 0012F728   0012F748 0046B819 0056337C 0000002C 00000000 003C8148 00F90004 00000000
    0046B819 0012F748   0012F854 00465D38 00000003 00536ACD 00000000 00533094 0012F76C 00563908 0000000F 0012F784
    00465D38 0012F854   0012F864 00401F44 004CD807 004C9120
    00401F44 0012F864   0012F884 0046B819 0056337C 00000027 00000000 003C8148 00F90007 000005AD
    0046B819 0012F884   0012F990 00465D38 00000003 005292BC 00000000 00521C10 006B0508 00000084 00000000 0056009F


Modules:
0x00400000 0x0017A000 C:\FWH905\samples\testmail.exe
0x77BE0000 0x00127000 C:\Windows\system32\ntdll.dll
0x76AD0000 0x000DC000 C:\Windows\system32\kernel32.dll
0x76E20000 0x000C6000 C:\Windows\system32\ADVAPI32.DLL
0x766C0000 0x000C3000 C:\Windows\system32\RPCRT4.dll
0x741D0000 0x00042000 C:\Windows\system32\WINSPOOL.DRV
0x765F0000 0x000AA000 C:\Windows\system32\msvcrt.dll
0x76520000 0x0004B000 C:\Windows\system32\GDI32.dll
0x76D20000 0x0009D000 C:\Windows\system32\USER32.dll
0x74100000 0x00085000 C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.6001.18000_none_886786f450a74a05\COMCTL32.DLL
0x76790000 0x00073000 C:\Windows\system32\COMDLG32.DLL
0x76DC0000 0x00059000 C:\Windows\system32\SHLWAPI.dll
0x770D0000 0x00B10000 C:\Windows\system32\SHELL32.dll
0x76F80000 0x00145000 C:\Windows\system32\OLE32.DLL
0x76BB0000 0x0008D000 C:\Windows\system32\OLEAUT32.DLL
0x75740000 0x00005000 C:\Windows\system32\MSIMG32.DLL
0x766A0000 0x0001E000 C:\Windows\system32\IMM32.DLL
0x76450000 0x000C8000 C:\Windows\system32\MSCTF.dll
0x77D20000 0x00009000 C:\Windows\system32\LPK.DLL
0x76570000 0x0007D000 C:\Windows\system32\USP10.dll
0x75040000 0x0019E000 C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.6002.18005_none_5cb72f96088b0de0\comctl32.dll
0x75590000 0x0003F000 C:\Windows\system32\uxtheme.dll
0x6F1F0000 0x00013000 C:\Windows\system32\mapi32.dll
0x6F6F0000 0x0000E000 C:\Program Files\Mozilla Thunderbird\mozMapi32_InUse.dll
0x76EF0000 0x00084000 C:\Windows\system32\CLBCatQ.DLL
0x757D0000 0x0003B000 C:\Windows\system32\rsaenh.dll
0x72120000 0x00007000 C:\Program Files\Mozilla Thunderbird\MapiProxy_InUse.dll
0x6D4F0000 0x000B0000 C:\Program Files\Mozilla Thunderbird\MOZCRT19.dll

Called from TMAIL:ACTIVATE(99) in .\source\classes\TMAIL.PRG
Called from DIRECTMESSAGE(72) in testmail.prg
Called from (b)EVAL(31)
Called from TBTNBMP:CLICK(443) in .\source\classes\BTNBMP.PRG
Called from TBTNBMP:LBUTTONUP(629) in .\source\classes\BTNBMP.PRG
Called from TWINDOW:HANDLEEVENT(0)
Called from TCONTROL:HANDLEEVENT(1453) in .\source\classes\CONTROL.PRG
Called from TBTNBMP:HANDLEEVENT(1283) in .\source\classes\BTNBMP.PRG
Called from _FWH(3333) in .\source\classes\WINDOW.PRG
Called from WINRUN(0)
Called from TWINDOW:ACTIVATE(952) in .\source\classes\WINDOW.PRG
Called from MAIN(38) in testmail.prg
------------------------------------------------------------------------
 


Servirá esto de algo? creo que es necesario el .map, no?
Saludos
Carlos Mora
http://harbouradvisor.blogspot.com/
StackOverflow http://stackoverflow.com/users/549761/carlos-mora
“If you think education is expensive, try ignorance"
Carlos Mora
 
Posts: 988
Joined: Thu Nov 24, 2005 3:01 pm
Location: Madrid, España

Re: Problemas con TMail y FWH 9.04

Postby mgsoft » Fri Oct 08, 2010 8:47 am

Hola,

¿Hay algún avance, pues este error lleva mucho tiempo sin corregirse?.

¿Estará para FW 9.10?

Gracias :D
Saludos,

Eduardo
User avatar
mgsoft
 
Posts: 422
Joined: Mon Aug 17, 2009 12:18 pm
Location: España

Re: Problemas con TMail y FWH 9.04

Postby mgsoft » Fri Oct 22, 2010 2:55 pm

Hola,

Alguna novedad?
Saludos,

Eduardo
User avatar
mgsoft
 
Posts: 422
Joined: Mon Aug 17, 2009 12:18 pm
Location: España

Re: Problemas con TMail y FWH 9.04

Postby Daniel Garcia-Gil » Wed Nov 17, 2010 2:44 pm

Carlos, mgsoft

este es el archivo mapi.c modificado
Code: Select all  Expand view

//  96-03-18 Michael Kocum
//
//  Translated German notes
//
//  Added Exchange flags
//
//  Changed ulRecipClass in MAPIAddress
//  to MAPI_TO to be compatible with FiveWin
//
//  Added a counter for loading MAPI.LIB
//  because MSMAIL 3.2 clears all pending
//  sessions when MAPI.DLL is loaded twice
//  and as a result, nothing is working as exspected.
//  ( Exchange and WFW have no problems )
//  As a result of this
//  every LOGON needs a LOGOFF or
//  the DLL will not released.
//
//  Changed MAPISendMail, MAPIResolveName,
//  MAPIAddress to let them work without needing
//  a LOGON first (MAPI does the logon in the fly).
//
//  The flag MAPI_LOGON_UI is set when no valid
//  MAPI session is established to let MAPI popup
//  an logon dialog if neccessary. Without this
//  MAPI returns an error if there is no default
//  in MSMAIL.INI
//
//  Changed the first paramter of MAPISendDocuments
//  to be Window Handle instead of Mapi Session Handle as
//  stated in the MAPI documentation
//
//  Added define for
//
//  Changed MAPILogoff to return a value in any case
//
//  Changed MAPILogon, MAPISendMail and MAPIDelete to
//  return -1 when the Log could not be loaded (old version)
//  returned a ULONG -1 which results in 65535
//
//  Fixed MAPIDelete to return MAPI_E_INVALID_SESSION when no
//  session is established
//

// defines a little bit other processing of MAPI_TO as FiveWin
// #define KOCUM


// define a error number above the one MSMAIL uses
#define ERR_CANT_LOAD_MAPI    60000

#ifdef __FLAT__
#undef  MAPILOGON
#define MAPILOGON  _MAPILOGON
#undef  MAPILOGOFF
#define MAPILOGOFF _MAPILOGOFF
#endif

#include <WinTen.h>
#include <Windows.h>
#include <ClipApi.h>
#include <Mapi.h>

#ifdef __FLAT__
#undef  MAPILOGON
#define MAPILOGON  MAPILOGON
#undef  MAPILOGOFF
#define MAPILOGOFF MAPILOGOFF
#undef  PASCAL
#define PASCAL
#endif

#ifdef __HARBOUR__
   #ifndef __C3__
      #include <hbapi.h>
      #include <hbstack.h>
      #define _VARRAYLEN(x)  hb_arrayLen(x)
      #define S_ARRAY ARRAY
   #endif
#endif

//
//  Exchange Flags
//
#define MAPI_PASSWORD_UI        0x00020000  /* prompt for password only     */
#define MAPI_ALLOW_OTHERS       0x00000008  /* Make this a shared session   */
#define MAPI_EXPLICIT_PROFILE   0x00000010  /* Don't use default profile    */
#define MAPI_EXTENDED           0x00000020  /* Extended MAPI Logon          */
#define MAPI_USE_DEFAULT        0x00000040  /* Use default profile in logon */

typedef unsigned short USHORT;
typedef BYTE * BYTEP;
typedef double XDOUBLE;

// #ifndef __FLAT__
#include <item.api>
// #endif

#ifndef __FLAT__
   #define MAPI_DLL "mapi.dll"
#else
   #define MAPI_DLL "mapi32.dll"
#endif

static LHANDLE lhMailHandle = 0L;
static ULONG   nMapiAccessCount = 0L;
static HINSTANCE hMapiLib = 0L;

//----------------------------------------------------------------------------//
BOOL static LoadMapiLib( void )
{
   // check if Mapi.DLL is loaded and don't load it twice

   if( hMapiLib >= ( HINSTANCE) 32 )
   {
      nMapiAccessCount ++ ;     // increment counter
      return TRUE ;
   }
   else
   {
      if((hMapiLib = LoadLibrary( MAPI_DLL )) >= (HINSTANCE) 32)
      {
         nMapiAccessCount ++ ;     // increment counter
         return TRUE ;
      }
   }
   return FALSE ;
}
//----------------------------------------------------------------------------//
void static FreeMapiLib( void )
{

   nMapiAccessCount -- ;     // decrement  counter

   // check if there are pending calls

   if( nMapiAccessCount )
   {

      // check if we have a closed all sessions

      if( lhMailHandle )
      {
         FreeLibrary( hMapiLib );
      }
   }
}
//----------------------------------------------------------------------------//
ULONG static FreeBuffer( LPVOID pv )
{
   ULONG rc = ERR_CANT_LOAD_MAPI;
   LPMAPIFREEBUFFER lpfnMAPIFreeBuffer;

   if( LoadMapiLib() )
   {

      lpfnMAPIFreeBuffer = ( LPMAPIFREEBUFFER ) GetProcAddress(hMapiLib,"MAPIFreeBuffer") ;

      rc = (*lpfnMAPIFreeBuffer)( pv ) ;

      FreeMapiLib();
   }

   return( rc ) ;
}
//----------------------------------------------------------------------------//

HB_FUNC( MAPILOGON )
{
   LPSTR szUserName = ( LPSTR ) IF( PCOUNT() >= 1 && ISCHAR( 1 ), hb_parc( 1 ), NULL );
   LPSTR szPassword = ( LPSTR ) IF( PCOUNT() >= 2 && ISCHAR( 2 ), hb_parc( 2 ), NULL );
   FLAGS nFlags     = IF( PCOUNT() >= 3 && ISNUM( 3 ) , hb_parnl( 3 ),
                      MAPI_LOGON_UI | MAPI_NEW_SESSION | MAPI_USE_DEFAULT );
   ULONG rc;
   LPMAPILOGON lpfnMAPILogon;

   if( LoadMapiLib() )
   {
      lpfnMAPILogon = ( LPMAPILOGON ) GetProcAddress( hMapiLib, "MAPILogon" );

      rc = ( *lpfnMAPILogon )( ( ULONG ) GetActiveWindow(), szUserName, szPassword,
           nFlags, 0, ( LPLHANDLE ) &lhMailHandle );

      FreeMapiLib();

      hb_retnl( rc );
   }
   else
   {
      hb_retnl( -1 );
   }
}
//----------------------------------------------------------------------------//

HB_FUNC( MAPILOGOFF )
{
   ULONG rc = ERR_CANT_LOAD_MAPI;
   LPMAPILOGOFF lpfnMAPILogoff;

   // Session had to exist

   if( lhMailHandle )
   {
      if( LoadMapiLib() )
      {

         lpfnMAPILogoff = ( LPMAPILOGOFF ) GetProcAddress(hMapiLib,"MAPILogoff") ;

         rc = (*lpfnMAPILogoff)( lhMailHandle, ( ULONG ) GetActiveWindow(),0, 0 ) ;
         lhMailHandle = 0;

         FreeMapiLib();
      }
   }
   hb_retl( rc ) ;
}
//----------------------------------------------------------------------------//

#ifdef __HARBOUR__
   HB_FUNC( MAPISENDMAIL )
#else
   HB_FUNC( MAPISENDMA )
#endif
{
   MapiMessage msg;
   MapiRecipDesc origin;
   MapiRecipDesc target[ 10 ];
   MapiFileDesc  FileDesc[ 10 ];
   WORD w, wLen;
   ULONG rc;
   LPMAPISENDMAIL lpfnMAPISendMail;
   FLAGS nFlags;

   memset( ( char * ) &msg,    0, sizeof( msg ) );
   memset( ( char * ) &origin, 0, sizeof( origin ) );
   memset( ( char * ) target,  0, sizeof( target ) );
   memset( ( char * ) FileDesc,0, sizeof( FileDesc ) );

   msg.ulReserved         = 0;
   msg.lpszSubject        = ( LPSTR ) IF( ISCHAR( 1 ), hb_parc( 1 ), NULL );
   msg.lpszNoteText       = ( LPSTR ) IF( ISCHAR( 2 ), hb_parc( 2 ), NULL );
   msg.lpszMessageType    = ( LPSTR ) IF( ISCHAR( 3 ), hb_parc( 3 ), NULL );
   msg.lpszDateReceived   = ( LPSTR ) IF( ISCHAR( 4 ), hb_parc( 4 ), NULL );
   // msg.lpszConversationID = IF( ISCHAR( 5 ), hb_parc( 5 ), NULL );
   msg.flFlags            = IF( ( ISLOGICAL( 6 ) && hb_parl( 6 ) ),
                                MAPI_RECEIPT_REQUESTED, 0 );

   if( PCOUNT() >= 8 && ISARRAY( 8 ) &&
       _VARRAYLEN( hb_param( 8, S_ARRAY ) ) )
   {
      origin.lpszName    = ( LPSTR ) hb_parvc( 8, 1 );
      origin.lpszAddress = ( LPSTR ) hb_parvc( 8, 2 );
      msg.lpOriginator   = &origin;
   }

   if( PCOUNT() >= 9 && ISARRAY( 9 ) &&
     ( wLen = _VARRAYLEN( hb_param( 9, S_ARRAY ) ) ) )
   {
      for( w = 0; w < wLen; w++ )
      {
         #ifndef __HARBOUR__
            _cAt( hb_param( 9, S_ARRAY ), w + 1, -1, _eval );
         #else
            hb_arrayGet( hb_param( 9, S_ARRAY ), w + 1, hb_stackReturnItem() );
         #endif
         target[ w ].lpszName     = ( LPSTR ) hb_parvc( -1, 1 );
         target[ w ].lpszAddress  = ( LPSTR ) hb_parvc( -1, 2 );

         #ifdef KOCUM
            target[ w ].ulRecipClass = hb_parvnl( -1, 3 ) ;
         #else
            target[ w ].ulRecipClass = IF( w == 0, MAPI_TO, MAPI_CC ); // hb_parnl( -1, 3 ) ;
         #endif
      }
      msg.nRecipCount = wLen;
      msg.lpRecips    = target;
   }

   if( PCOUNT() >= 10 && ISARRAY( 10 ) &&
     ( wLen = _VARRAYLEN( hb_param( 10, S_ARRAY ) ) ) )
   {
      for( w = 0; w < wLen; w++ )
      {
         #ifndef __HARBOUR__
            _cAt( hb_param( 10, S_ARRAY ), w + 1, -1, _eval );
         #else
            hb_arrayGet( hb_param( 10, S_ARRAY ), w + 1, hb_stackReturnItem() );
         #endif
         FileDesc[ w ].ulReserved      = 0 ;
         FileDesc[ w ].lpszPathName    = ( LPSTR ) hb_parvc( -1, 1 );
         FileDesc[ w ].lpszFileName    = ( LPSTR ) hb_parvc( -1, 2 );
         FileDesc[ w ].nPosition       = -1 ;
      }
      msg.nFileCount = wLen;
      msg.lpFiles  = FileDesc;
   }

   if( LoadMapiLib() )
   {
      lpfnMAPISendMail = ( LPMAPISENDMAIL ) GetProcAddress( hMapiLib, "MAPISendMail");


      nFlags = IF( ( ISLOGICAL( 7 ) && hb_parl( 7 ) ), MAPI_DIALOG, 0 ) ;

      // Set flag when no MAPI session
      if( ! lhMailHandle )
      {
         nFlags |= MAPI_LOGON_UI ;
      }


      rc =  (*lpfnMAPISendMail)( lhMailHandle, ( unsigned long ) GetActiveWindow(), &msg,
                         nFlags,0) ;

      FreeMapiLib();
      hb_retnl( rc ) ;
   }
   else
   {
      hb_retnl( -1 );
   }
}
//----------------------------------------------------------------------------//
//
// Para 1: Name
//
#ifdef __HARBOUR__
   HB_FUNC( MAPIRESOLVENAME )
#else
   HB_FUNC( MAPIRESOLV )
#endif
{
   LPSTR szName = ( LPSTR ) IF( PCOUNT() == 1 && ISCHAR(1), hb_parc( 1 ), NULL );
   lpMapiRecipDesc lppNewRecips;
   ULONG rc = ERR_CANT_LOAD_MAPI;
   LPMAPIRESOLVENAME lpfnMAPIResolveName;
   FLAGS nFlags = MAPI_DIALOG ;

   if( LoadMapiLib() )
   {

      lpfnMAPIResolveName = ( LPMAPIRESOLVENAME ) GetProcAddress(hMapiLib,"MAPIResolveName") ;

      if( ! lhMailHandle )
      {
         nFlags |= MAPI_LOGON_UI ;
      }

      rc = (*lpfnMAPIResolveName)( lhMailHandle, ( unsigned long ) GetActiveWindow(), szName, nFlags ,0, &lppNewRecips ) ;

      FreeMapiLib();
   }

   if( rc == SUCCESS_SUCCESS)
   {

      hb_retc(lppNewRecips[0].lpszAddress);

      FreeBuffer(lppNewRecips);

   }
   else
   {
      hb_retc("");
   }
}
//----------------------------------------------------------------------------//
// Para 1: Caption
// Para 2: Label
// Para 3: Count of EditField
// Para 4: Array for defaults addresses
//
#ifdef __HARBOUR__
   HB_FUNC( MAPIADDRESS )
#else
   HB_FUNC( MAPIADDRES )
#endif
{
   MapiRecipDesc lpDefRecip[ 10 ];
   lpMapiRecipDesc lppNewRecips;
   WORD w ;
   WORD wLen;  // Null vorbelegen
   ULONG i ;
   ULONG nDefCount = 0;  // Null vorbelegen
   ULONG nNewCount   = 0;
   LPSTR szCaption   = ( LPSTR ) IF( PCOUNT() >= 1 && ISCHAR(1), hb_parc( 1 ), NULL );
   LPSTR szLabels    = ( LPSTR ) IF( PCOUNT() >= 2 && ISCHAR(1), hb_parc( 2 ), NULL ) ;
   ULONG nEditFields = IF( PCOUNT() >= 3 && ISNUM(3) , hb_parnl( 3 ), 1 ) ;
   ITEM nTemp,aTemp,cTemp,aRet ;
   ULONG rc = ERR_CANT_LOAD_MAPI;
   LPMAPIADDRESS lpfnMAPIAddress;
   FLAGS nFlags = 0 ;

   memset( ( char * ) lpDefRecip, 0, sizeof( lpDefRecip ) );

   // Set predefined values

   if( ISARRAY( 4 ) &&  _VARRAYLEN( hb_param( 4, S_ARRAY ) ) )
   {

      wLen = _VARRAYLEN( hb_param( 4, S_ARRAY ) ) ;

      for( w = 0; w < wLen; w++ )
      {
         #ifndef __HARBOUR__
            _cAt( hb_param( 4, S_ARRAY ), w + 1, -1, _eval );
         #else
            hb_arrayGet( hb_param( 4, S_ARRAY ), w + 1, hb_stackReturnItem() );
         #endif
         lpDefRecip[ w ].lpszName     = ( LPSTR ) hb_parvc( -1, 1 );
         lpDefRecip[ w ].lpszAddress  = ( LPSTR ) hb_parvc( -1, 2 );

         #ifdef KOCUM
            lpDefRecip[ w ].ulRecipClass = hb_parvnl( -1, 3 ) ;
         #else
            lpDefRecip[ w ].ulRecipClass = MAPI_TO ;
         #endif
      }

      if( wLen > 0 )
      {
         nDefCount = wLen ;
      }

   }

   if( LoadMapiLib() )
   {

      lpfnMAPIAddress = ( LPMAPIADDRESS ) GetProcAddress(hMapiLib,"MAPIAddress") ;

      if( ! lhMailHandle )
      {
         nFlags |= MAPI_LOGON_UI ;
      }

      rc = (*lpfnMAPIAddress)( lhMailHandle, ( unsigned long ) GetActiveWindow(), szCaption, nEditFields,
            szLabels, nDefCount, lpDefRecip, nFlags, 0, &nNewCount, &lppNewRecips) ;

      FreeMapiLib();
   }

   if( rc == SUCCESS_SUCCESS)
   {

      aRet = _itemArrayNew( nNewCount );         // Create new array of that len

      for ( i = 1; i <= nNewCount; i++ )             // Iterate through elements
      {

         aTemp = _itemArrayNew( 3 );            // Create new array of that len

         cTemp = _itemPutC( NULL,lppNewRecips[ i - 1].lpszName);
         _itemArrayPut( aTemp, 1, cTemp );
         _itemRelease( cTemp );

         // check address

         if( lppNewRecips[ i - 1].lpszAddress )
         {
            cTemp = _itemPutC( NULL,lppNewRecips[ i - 1].lpszAddress);
         }
         else
         {
            cTemp = _itemPutC( NULL,"");
         }

         _itemArrayPut( aTemp, 2, cTemp );
         _itemRelease( cTemp );

         nTemp = _itemPutNL( NULL,lppNewRecips[ i - 1].ulRecipClass);
         _itemArrayPut( aTemp, 3, nTemp );
         _itemRelease( nTemp );

         _itemArrayPut( aRet, i, aTemp );
         _itemRelease( aTemp );

      }

      _itemReturn ( aRet );
      _itemRelease( aRet );                  //    release "aRet"

      FreeBuffer(lppNewRecips);

   }
   else
   {

      aRet = _itemArrayNew( 0 );         // Create new array of that len
      _itemReturn ( aRet );
      _itemRelease( aRet );              //    release "aRet"

   }
}
//----------------------------------------------------------------------------//
//
// Para 1: Typ  ("IPM" does not work )
// Para 2: Flags
// Para 3: Message ID
//
#ifdef __HARBOUR__
   HB_FUNC( MAPIFINDNEXT )
#else
   HB_FUNC( MAPIFINDNE )
#endif
{
   LPSTR szTyp           = ( LPSTR ) IF( ISCHAR(1), hb_parc( 1 ) , NULL );
   FLAGS flFlags         = IF( ISNUM(2) , hb_parnl( 2 ), 0 );
   LPSTR szSeedMessageID = ( LPSTR ) IF( ISCHAR(3), hb_parc( 3 ) , NULL );
   char szMessageID [ 254 ] ;
   ULONG rc = ERR_CANT_LOAD_MAPI;
   LPMAPIFINDNEXT lpfnMAPIFindNext;

   // Logon has to be done, because further calls will need the same session

   if( lhMailHandle )
   {

      strcpy( szMessageID, "" );

      if( LoadMapiLib() )
      {

         lpfnMAPIFindNext = ( LPMAPIFINDNEXT ) GetProcAddress(hMapiLib,"MAPIFindNext") ;

         rc = (*lpfnMAPIFindNext)( lhMailHandle, ( unsigned long ) GetActiveWindow(), szTyp,
                                      szSeedMessageID, flFlags, 0, szMessageID ) ;

         FreeMapiLib();
      }

      if( rc == SUCCESS_SUCCESS )
      {
         hb_retc(szMessageID);
      }
      else
      {
         hb_retc("");
      }
   }
}
//----------------------------------------------------------------------------//
//
// Para 1: Message ID
// Para 2: Flags
//

#ifdef __HARBOUR__
   HB_FUNC( MAPIREADMAIL )
#else
   HB_FUNC( MAPIREADMA )
#endif
{
   FLAGS flFlags     = IF( ISNUM(2) , hb_parnl( 2 ), MAPI_ENVELOPE_ONLY | MAPI_SUPPRESS_ATTACH | MAPI_PEEK);
   LPSTR szMessageID = ( LPSTR ) IF( ISCHAR(1), hb_parc( 1 ) , NULL );
   lpMapiMessage FAR *lppMapiMess;
   lpMapiMessage lpMapiMess;
   ITEM nTemp,cTemp,aRet,aTemp,aAdr ;
   ULONG i ;
   ULONG rc = ERR_CANT_LOAD_MAPI;
   LPMAPIREADMAIL lpfnMAPIReadMail;

   // Logon has to be done, because the ID needs to be from the same session

   if( lhMailHandle )
   {

      lppMapiMess = (lpMapiMessage FAR *) &lpMapiMess;

      if( LoadMapiLib() )
      {

         lpfnMAPIReadMail = ( LPMAPIREADMAIL ) GetProcAddress(hMapiLib,"MAPIReadMail") ;

         rc = (*lpfnMAPIReadMail)( lhMailHandle, ( unsigned long ) GetActiveWindow(), szMessageID,
                         flFlags,0,lppMapiMess) ;

         FreeMapiLib();
      }

      if( rc == SUCCESS_SUCCESS )
      {

         //  Subject             1
         //  NoteText            2
         //  Type                3
         //  Date                4
         //  Flags               5
         //  Recipient  (To)     6
         //  Originator (From)   7


         aRet = _itemArrayNew( 7 ) ;

         if( lpMapiMess->lpszSubject )
         {
            cTemp = _itemPutC(NULL,lpMapiMess->lpszSubject);
         }
         else
         {
            cTemp = _itemPutC( NULL,"");
         }

         _itemArrayPut( aRet, 1, cTemp );
         _itemRelease( cTemp );

         //
         // Testen ob NoteText gekommen ist
         //
         if( lpMapiMess->lpszNoteText )
         {
            cTemp = _itemPutC(NULL,lpMapiMess->lpszNoteText);
         }
         else
         {
            cTemp = _itemPutC( NULL,"");
         }

         _itemArrayPut( aRet, 2, cTemp );
         _itemRelease( cTemp );



         cTemp = _itemPutC(NULL,lpMapiMess->lpszMessageType);
         _itemArrayPut( aRet, 3, cTemp );
         _itemRelease( cTemp );

         if( lpMapiMess->lpszDateReceived )
         {
            cTemp = _itemPutC(NULL,lpMapiMess->lpszDateReceived);
         }
         else
         {
            cTemp = _itemPutC( NULL,"");
         }
         _itemArrayPut( aRet, 4, cTemp );
         _itemRelease( cTemp );

         nTemp = _itemPutNL(NULL,lpMapiMess->flFlags);
         _itemArrayPut( aRet, 5, nTemp );
         _itemRelease( nTemp );

         //
         // Add recipients
         //

         aAdr = _itemArrayNew( lpMapiMess->nRecipCount );         // Create new array of that len

         for ( i = 1; i <= lpMapiMess->nRecipCount; i++ )             // Iterate through elements
         {

            aTemp = _itemArrayNew( 3 );            // Create new array of that len

            if( lpMapiMess->lpRecips[ i - 1].lpszName )
            {
               cTemp = _itemPutC( NULL,lpMapiMess->lpRecips[ i - 1].lpszName);
            }
            else
            {
               cTemp = _itemPutC( NULL,"");
            }
            _itemArrayPut( aTemp, 1, cTemp );
            _itemRelease( cTemp );

            // Check if adress is ok
            // ( local groups have no adress )

            if( lpMapiMess->lpRecips[ i - 1].lpszAddress )
            {
               cTemp = _itemPutC( NULL,lpMapiMess->lpRecips[ i - 1].lpszAddress);
            }
            else
            {
               cTemp = _itemPutC( NULL,"");
            }

            _itemArrayPut( aTemp, 2, cTemp );
            _itemRelease( cTemp );

            nTemp = _itemPutNL( NULL,lpMapiMess->lpRecips[ i - 1].ulRecipClass);
            _itemArrayPut( aTemp, 3, nTemp );
            _itemRelease( nTemp );

            _itemArrayPut( aAdr, i, aTemp );
            _itemRelease( aTemp );

         }

         _itemArrayPut( aRet, 6, aAdr );
         _itemRelease( aAdr );

         //
         // Add FROM
         //

         aAdr = _itemArrayNew( 1 );         // Create new array of that len

         aTemp = _itemArrayNew( 3 );            // Create new array of that len

         if( lpMapiMess->lpOriginator->lpszName )
         {
            cTemp = _itemPutC( NULL,lpMapiMess->lpOriginator->lpszName);
         }
         else
         {
            cTemp = _itemPutC( NULL,"");
         }
         _itemArrayPut( aTemp, 1, cTemp );
         _itemRelease( cTemp );

         // Check adress

         if( lpMapiMess->lpOriginator->lpszAddress )
         {
            cTemp = _itemPutC( NULL,lpMapiMess->lpOriginator->lpszAddress);
         }
         else
         {
            cTemp = _itemPutC( NULL,"");
         }

         _itemArrayPut( aTemp, 2, cTemp );
         _itemRelease( cTemp );

         nTemp = _itemPutNL( NULL,lpMapiMess->lpOriginator->ulRecipClass);
         _itemArrayPut( aTemp, 3, nTemp );
         _itemRelease( nTemp );

         _itemArrayPut( aAdr, 1, aTemp );
         _itemRelease( aTemp );


         _itemArrayPut( aRet, 7, aAdr );
         _itemRelease( aAdr );


         _itemReturn ( aRet );
         _itemRelease( aRet );                  //    release "aRet"

         rc = FreeBuffer(lpMapiMess);


         if( rc == SUCCESS_SUCCESS )
         {
         }
         else
         {
            MessageBox( 0, "MAPI memory not released!", "Error", 0 );
         }

      }
      else
      {
         aRet = _itemArrayNew( 0 );         // Create new array of that len
         _itemReturn ( aRet );
         _itemRelease( aRet );                  //    release "aRet"
      }
   }
   else
   {
      // Better return NIL, so that we know in the case of an error

      // aRet = _itemArrayNew( 0 );         // Create new array of that len
      // _itemReturn ( aRet );
      // _itemRelease( aRet );                  //    release "aRet"
   }
}
//----------------------------------------------------------------------------//
//
// Para 1: ID der Message
//
#ifdef __HARBOUR__
   HB_FUNC( MAPIDELETEMAIL )
#else
   HB_FUNC( MAPIDELETE )
#endif
{
   LPSTR szMessageID = ( LPSTR ) IF( ISCHAR(1), hb_parc( 1 ) , NULL );
   ULONG rc;
   LPMAPIDELETEMAIL lpfnMAPIDeleteMail;

   // Logon has to be done, because the ID needs to be from the same session

   if( lhMailHandle )
   {

      if( LoadMapiLib() )
      {
         lpfnMAPIDeleteMail = ( LPMAPIDELETEMAIL ) GetProcAddress(hMapiLib,"MAPIDeleteMail") ;

         rc = (*lpfnMAPIDeleteMail)( lhMailHandle, ( unsigned long ) GetActiveWindow(),
                                     szMessageID,0,0) ;

         FreeMapiLib();
         hb_retnl( rc ) ;
      }
      else
      {
         hb_retnl( -1 );
      }
   }
   else
   {
      hb_retnl( MAPI_E_INVALID_SESSION ) ;
   }
}
//----------------------------------------------------------------------------//

#ifdef __HARBOUR__
   HB_FUNC( MAPISENDDOCUMENTS ) // CUMENTS( nUiParam, cDelimiters, cFilePaths,
                        //      cFileNames, nReserved ) --> nResult
#else
   HB_FUNC( MAPISENDDO ) // CUMENTS( nUiParam, cDelimiters, cFilePaths,
                        //      cFileNames, nReserved ) --> nResult
#endif
{
   LPMAPISENDDOCUMENTS lpfnMAPISendDocuments;

   if( LoadMapiLib() )
   {
      lpfnMAPISendDocuments = ( LPMAPISENDDOCUMENTS ) GetProcAddress( hMapiLib,
                                              "MAPISendDocuments" );

      hb_retnl( ( * lpfnMAPISendDocuments )( ( unsigned long ) GetActiveWindow(), ",", 0,
              ( char * ) hb_parc( 1 ), 0 ) );
      FreeMapiLib( );
   }
   else
   {
      hb_retnl( -1 );
   }
}
//----------------------------------------------------------------------------//
 


para mas comodidad, dejo los obj que podran ser reemplazados dentro de fivehc.lib

borland bcc55, borland bcc582 y msn32 (pronto subo para 64 no lo he probado aun)

descarga el ejemplo prg y ejecutable
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: Problemas con TMail y FWH 9.04

Postby devtuxtla » Fri Nov 26, 2010 5:40 am

Hola Daniel

usando esta version del .obj que nos enviaste (Gracias) me da el siguiente error:

Error: Unresolved external '_hb_parvc' referenced from

Actualmete uso la version de fwh 7.12, desde esta version persiste el problema...

Sera posible generar un .obj para esta (old) version?

Saludos
Visite Chiapas, el paraiso de México.
devtuxtla
 
Posts: 392
Joined: Tue Jul 29, 2008 1:55 pm

Re: Problemas con TMail y FWH 9.04

Postby Daniel Garcia-Gil » Fri Nov 26, 2010 10:20 am

Saludos

Agrega esto en el proyecto

Code: Select all  Expand view
#pragma BEGINDUMP
#include <hbapi.h>

char * hb_parvc( int iParam, int iIndex )
{
   return ( char * ) hb_parc( iParam, iIndex );
}  

#pragma ENDDUMP
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 140 guests