Problems with memory allocation

Problems with memory allocation

Postby sambomb » 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: Select all  Expand view

   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: Select all  Expand view

****************************************************************************
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

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
User avatar
sambomb
 
Posts: 388
Joined: Mon Oct 13, 2008 11:26 am
Location: Itaocara - RJ - Brasil

Re: Problems with memory allocation

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

Re: Problems with memory allocation

Postby lailton.webmaster » 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
lailton.webmaster
 
Posts: 603
Joined: Sun May 04, 2008 8:44 pm

Re: Problems with memory allocation

Postby sambomb » Fri Oct 02, 2009 2: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

Code: Select all  Expand view

#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 )));

    }
}
 


Call

Code: Select all  Expand view

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
User avatar
sambomb
 
Posts: 388
Joined: Mon Oct 13, 2008 11:26 am
Location: Itaocara - RJ - Brasil

Re: Problems with memory allocation

Postby Antonio Linares » Fri Oct 02, 2009 4:28 pm

Try it this way:
Code: Select all  Expand view

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

Re: Problems with memory allocation

Postby sambomb » Fri Oct 02, 2009 7: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
User avatar
sambomb
 
Posts: 388
Joined: Mon Oct 13, 2008 11:26 am
Location: Itaocara - RJ - Brasil

Re: Problems with memory allocation

Postby sambomb » Mon Oct 05, 2009 6: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
User avatar
sambomb
 
Posts: 388
Joined: Mon Oct 13, 2008 11:26 am
Location: Itaocara - RJ - Brasil


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 60 guests