FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Problems with memory allocation
Posts: 389
Joined: Mon Oct 13, 2008 11:26 AM
Problems with memory allocation
Posted: Thu Oct 01, 2009 11:33 PM
Hello, I use xharbour 1.1.0 and am having problems with memory allocation, I call a DLL (Daruma32.DLL) that I send as reference


Code (fw): Select all Collapse
   DLL32 FUNCTION D_MFDINFOR(cIndice AS STRING, @cInfo AS STRING); //-- Samir 24/8/2009
         AS _INT PASCAL FROM "Daruma_FIMFD_RetornaInformacao";
         LIB nLib32


Call
Code (fw): Select all Collapse
****************************************************************************
METHOD PegaNumeroSerie() CLASS TFISPRN
****************************************************************************
*
* Obter o numero de serie da impressora
* Parametros:
* Retorno: nLastResult
*
* Autor: Samir
* 24/8/2009 - 14:11:51
*
****************************************************************************
Private cNumeroSerie := ""

   cNumeroSerie := Space(15)

   if ::EcfType == ecf_daruma
      /* 
      if ::cModelo == "1"  //-- Samir 14/9/2009

         ::nLastResult := D_NUMSERIE(@cNumeroSerie)
         cNumeroSerie := SZero(cNumeroSerie,8)
         
         Alert("Modelo 1")

      else
     */ 
         cNumeroSerie := Space(20)  //-- Samir 30/9/2009
         ::nLastResult := D_MFDINFOR("78",@cNumeroSerie)

         Alert("Modelo 2")

      //end
      //-- DadosVar = Function that use a MsgInfo to show the type, length and value of the var
      DadosVar(cNumeroSerie,.T.,"cNumeroSerie parametro")
      //-- Verify the success of the printer
      If ::nLastResult = 1

         Alert("CAIU")
         Try//-- RemNaoImp, remove non-printables characters(Chr() 1 a 32) and apply PadR() to the var
            ::cNumeroSerie := RemNaoImp(cNumeroSerie,.T.)
         catch
            Msg("Erro!")
         end

      end
      
      DadosVar(::cNumeroSerie,.T.,"::cNumeroSerie dados")

   end

return ::nLastResult
/*------------------------------------------------------------------------*/



If I execute this proc, until now I had 6 different results:

  • Return a text that isn't associated with the related and isn't instanced in this sequence in any place, in my case "Report X DAV "[/*]
  • Return strange characters, such */+..~¨ 41 [/*]
  • Return empty [/*]
  • Close abruptely the program without sending error message [/*]
  • Close abruptely the program and request error sending to Windows [/*]
  • Return the serial number of the printer [/*]
    [/list:u]

    Someone knows how can I fix this? I'm trying to solve it for a few days, I need so much to solve it as soon as possible!
Email: SamirSSabreu@gmail.com
xHarbour 1.2.3 + Fwhh 20.2
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Problems with memory allocation
Posted: Fri Oct 02, 2009 12:04 AM

Samir,

Try it again removing PASCAL from the DLL32 declaration

(In FWH DLL32 is no longer needed. Just use DLL ... as we are in 32 bits)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 603
Joined: Sun May 04, 2008 08:44 PM
Re: Problems with memory allocation
Posted: Fri Oct 02, 2009 12:20 AM

Try this.

DLL FUNCTION DaMFDInf( inVar AS STRING, @outVar AS STRING );
AS LONG PASCAL FROM "Daruma_FIMFD_RetornaInformacao" LIB nLib32

Posts: 389
Joined: Mon Oct 13, 2008 11:26 AM
Re: Problems with memory allocation
Posted: Fri Oct 02, 2009 02:23 PM
The trouble isn't in the declaration of the DLL call, I use this call in many other places, but only in this especific case i'm having trouble...

In my app (16 bits) with FW 2.6 if I call the function twice I get the result that I need, any advice that can help me?

I already tried to declare this call in C but i got the same result

<div class="c" id="{CB}" style="font-family: monospace;">
#include "windows.h"
#include "hbapi.h"

typedef long (WINAPI * _DARUMA_FIMFD_RETORNAINFORMACAO)( char*, char* );

static     HINSTANCE handle = NULL;

HB_FUNC(INICIADLLDARUMA)
{
handle = LoadLibrary("Daruma32.dll");
}

HB_FUNC(TERMINADLLDARUMA)
{
        FreeLibrary( handle );
}


HB_FUNC( DARUMA_FIMFD_RETORNAINFORMACAO )
{


    if (handle)
    {
        _DARUMA_FIMFD_RETORNAINFORMACAO pFunc;
        pFunc = (_DARUMA_FIMFD_RETORNAINFORMACAO) GetProcAddress(handle, "Daruma_FIMFD_RetornaInformacao");

        hb_retni(pFunc( hb_parc( 1 ),hb_parc( 2 )));

    }
}
 </div>


Call

Code (fw): Select all Collapse
Function Test()
Local c123Buffer := ""

   INICIADLLDARUMA()

   C123BUFFER := SPACE(20)
   
   DARUMA_FIMFD_RETORNAINFORMACAO("78",@C123BUFFER)
   
   TERMINADLLDARUMA()
   
   MsgInfo(C123BUFFER,"Info")

Return
Email: SamirSSabreu@gmail.com
xHarbour 1.2.3 + Fwhh 20.2
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Problems with memory allocation
Posted: Fri Oct 02, 2009 04:28 PM
Try it this way:
Code (fw): Select all Collapse
#include "windows.h"
#include "hbapi.h"

typedef long (WINAPI * _DARUMA_FIMFD_RETORNAINFORMACAO)( char*, char* );

static HINSTANCE handle = NULL;

HB_FUNC(INICIADLLDARUMA)
{
   handle = LoadLibrary("Daruma32.dll");
}

HB_FUNC(TERMINADLLDARUMA)
{
        FreeLibrary( handle );
}

HB_FUNC( DARUMA_FIMFD_RETORNAINFORMACAO )
{
    if (handle)
    {
        _DARUMA_FIMFD_RETORNAINFORMACAO pFunc;
        pFunc = (_DARUMA_FIMFD_RETORNAINFORMACAO) GetProcAddress(handle, "Daruma_FIMFD_RetornaInformacao");

        hb_retni( pFunc( hb_parc( 1 ),hb_parc( 2 ) ) );
        hb_storc( hb_parc( 2 ), 2 );
    }
}
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 389
Joined: Mon Oct 13, 2008 11:26 AM
Re: Problems with memory allocation
Posted: Fri Oct 02, 2009 07:50 PM

Linares, it don't solve my trouble....
With this declaration I receive strange characters too....

Any other tip?

Email: SamirSSabreu@gmail.com
xHarbour 1.2.3 + Fwhh 20.2
Posts: 389
Joined: Mon Oct 13, 2008 11:26 AM
Re: Problems with memory allocation
Posted: Mon Oct 05, 2009 06:20 PM

Linares, you know some function to reserve a specific address in memory and allocate a variable at this address?

Email: SamirSSabreu@gmail.com
xHarbour 1.2.3 + Fwhh 20.2

Continue the discussion