ENVPARAM

ENVPARAM

Postby thefull » Tue Feb 28, 2012 10:59 am

Buenas, he encontrado un código, solo para Windows, que podría usarse para crear la funcion de las CLTOOLS, ENVPARAM()
http://www.ousob.com/ng/tools1-3/ngb9607.php

Code: Select all  Expand view
#pragma BEGINDUMP

#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <hbapi.h>


HB_FUNC( ENVPARAM )
{
    LPTSTR lpszVariable;
    LPTCH lpvEnv;
    LPTSTR pszBuffer = NULL;

    // Get a pointer to the environment block.
    lpvEnv = GetEnvironmentStrings();

    // If the returned pointer is NULL, exit.
    if (lpvEnv == NULL)
    {
        printf("GetEnvironmentStrings failed (%d)\n", GetLastError());
        return ;
    }

    // Variable strings are separated by NULL byte, and the block is
    // terminated by a NULL byte.
    lpszVariable = (LPTSTR) lpvEnv;

    while (*lpszVariable)
    {
        _tprintf(TEXT("%s\n"), lpszVariable);
        lpszVariable += lstrlen(lpszVariable) + 1;
    }
    FreeEnvironmentStrings(lpvEnv);
}

#pragma ENDDUMP


Solo queda que devuelva la lista donde el separador de las variables es un retorno de carro.

¿ Alguien puede add el código que falta ? Thanks!
Y de paso sería conveniente enviarlo para harbour para que lo add al sistema, aunque una vez terminado, ya lo envio yo.
Saludos
Rafa Carmona ( rafa.thefullARROBAgmail.com___quitalineas__)
User avatar
thefull
 
Posts: 729
Joined: Fri Oct 07, 2005 7:42 am
Location: Barcelona

Re: ENVPARAM

Postby Daniel Garcia-Gil » Tue Feb 28, 2012 12:33 pm

Rafa

Prueba de esta manera...

Code: Select all  Expand view

#include "fivewin.ch"

function main()
   local a
   a = hb_ATokens( EnvParam(), CRLF )
   XBROWSE( A )
return nil

#pragma BEGINDUMP

#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <hbapi.h>

char * LToStr( long );

HB_FUNC( ENVPARAM )
{
    LPTSTR lpszVariable;
    LPTCH lpvEnv;
    char * pszBuffer = NULL;
    int iLastLen = 0;
   
    // Get a pointer to the environment block.
    lpvEnv = GetEnvironmentStrings();

    // If the returned pointer is NULL, exit.
    if (lpvEnv == NULL)
    {
        printf("GetEnvironmentStrings failed (%d)\n", GetLastError());
        return ;
    }

    // Variable strings are separated by NULL byte, and the block is
    // terminated by a NULL byte.
    lpszVariable = (LPTSTR) lpvEnv;

    while (*lpszVariable)
    {
          char * newBuffer;
          int iLen = lstrlen( lpszVariable );
        pszBuffer = hb_xrealloc( pszBuffer, iLastLen + iLen + 2 );        
        hb_xmemcpy( pszBuffer+iLastLen, lpszVariable, iLen );
        hb_xmemcpy( pszBuffer+iLastLen+iLen, "\r\n", 2 );
        iLastLen += iLen + 2;        
        lpszVariable += lstrlen(lpszVariable) + 1;
       
    }
    FreeEnvironmentStrings(lpvEnv);
   
    hb_retc( pszBuffer );
}

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

Re: ENVPARAM

Postby thefull » Tue Feb 28, 2012 12:39 pm

Muchísimas gracias!!!
Saludos
Rafa Carmona ( rafa.thefullARROBAgmail.com___quitalineas__)
User avatar
thefull
 
Posts: 729
Joined: Fri Oct 07, 2005 7:42 am
Location: Barcelona


Return to To do - WishList / Por hacer - Peticiones

Who is online

Users browsing this forum: No registered users and 3 guests