Page 1 of 1

Func C GetVolumeInformation()

Posted: Fri Jan 08, 2016 12:39 pm
by ndarz
Esta funcion en c, se compila perfectamente en HMG.3.0.28, pero no funciona con versiones posteriores, la probe con la 3.3.1 en adelante, alguien sabe en que cambio, el problema esta hasta donde alcanza mi conocimiento (creo), en hbapi.h.

Puede que ya haya una funcion propia de HMG que ya haga esto, si alguien sabe?
with the power of google translator
This function in C, compiled in HMG.3.0.28 perfectly, but does not work with later versions, I tried the 3.3.1 on, anyone knows that change, the problem is as far as my knowledge (I think) in hbapi.h.

You may already have a function that HMG own and do this, if anyone knows?

Code: Select all

#pragma BEGINDUMP 
#include <windows.h> 
#include "hbapi.h" 
#include "hbapiitm.h" 
 
HB_FUNC(GETVOLUMEINFORMATION) 
{ 
	char *VolumeNameBuffer     = (char *) hb_xgrab( MAX_PATH ) ; 
	DWORD VolumeSerialNumber ; 
	DWORD MaximumComponentLength ; 
	DWORD FileSystemFlags ; 
	char *FileSystemNameBuffer = (char *) hb_xgrab( MAX_PATH ) ; 
	BOOL bRet ; 
	bRet = GetVolumeInformation( ISNIL(1) ? NULL : (LPCTSTR) hb_parc(1) , 
			(LPTSTR) VolumeNameBuffer, 
			MAX_PATH, 
			&VolumeSerialNumber, 
			&MaximumComponentLength, 
			&FileSystemFlags, 
			(LPTSTR)FileSystemNameBuffer, 
			MAX_PATH ) ; 
if ( bRet  ) 
{ 
    if ( ISBYREF( 2 ) )  hb_storc ((char *) VolumeNameBuffer, 2 ) ; 
    if ( ISBYREF( 3 ) )  hb_stornl( (LONG)  VolumeSerialNumber, 3 ) ; 
    if ( ISBYREF( 4 ) )  hb_stornl( (LONG)  MaximumComponentLength, 4 ) ; 
    if ( ISBYREF( 5 ) )  hb_stornl( (LONG)  FileSystemFlags, 5 ) ; 
    if ( ISBYREF( 6 ) )  hb_storc ((char *) FileSystemNameBuffer, 6 ) ; 
} 
	hb_retl(bRet); 
	hb_xfree( VolumeNameBuffer ); 
	hb_xfree( FileSystemNameBuffer ); 
} 
#pragma ENDDUMP 
Un ejemplo compilable.

Code: Select all

#include "hmg.ch" 
 
Function Main 
 	LOCAL cUni    :="D:\" 
	LOCAL cVolName :="VOLUMEN DEL DISCO" 
	LOCAL nSerNum := 1 
	LOCAL nMaxName:= 1 
	LOCAL nFlags  := 1 
	LOCAL cFATName:="TIPO DE FAT " 
      
	DEFINE WINDOW Win_1 ; 
		AT 0,0 ; 
		WIDTH  600 ; 
		HEIGHT 270 ; 
		TITLE 'Lectura del Numero de Serie de un Disco' ; 
		MAIN  
 
		GetVolumeInformation(cUni,@cVolName,@nSerNum,@nMaxName,@nFlags,@cFATName) 
 
		@ 030,120 LABEL  Label_01 VALUE  'Unidad  de  disco:  '+cUni WIDTH 600 HEIGHT 020 FONT "Arial" SIZE 10 
		@ 060,120 LABEL  Label_02 VALUE  'Etiqueta  de  Volumen:  '+cVolName WIDTH 600 HEIGHT 020 FONT "Arial" SIZE 10 
		@ 090,120 LABEL  Label_03 VALUE  'Numero de Serie:  '+STR(nSerNum) WIDTH 600 HEIGHT 020 FONT "Arial" SIZE 10 
		@ 120,120 LABEL  Label_04 VALUE  'Maximo de caracteres del Nombre:  '+STR(nMaxName) WIDTH 600 HEIGHT 020 FONT "Arial" SIZE 10 
		@ 150,120 LABEL  Label_05 VALUE  'Numero  de  Banderas:  '+STR(nFlags) WIDTH 600 HEIGHT 020 FONT "Arial" SIZE 10
		@ 180,120 LABEL  Label_06 VALUE  'Tipo  de  FAT:  '+cFATName WIDTH 600 HEIGHT 020 FONT "Arial" SIZE 10 
 
	END WINDOW 
 
   ACTIVATE WINDOW Win_1
 
Return 
*------------ 
#pragma BEGINDUMP 
#include <windows.h> 
#include "hbapi.h" 
#include "hbapiitm.h" 
 
HB_FUNC(GETVOLUMEINFORMATION) 
{ 
	char *VolumeNameBuffer     = (char *) hb_xgrab( MAX_PATH ) ; 
	DWORD VolumeSerialNumber ; 
	DWORD MaximumComponentLength ; 
	DWORD FileSystemFlags ; 
	char *FileSystemNameBuffer = (char *) hb_xgrab( MAX_PATH ) ; 
	BOOL bRet ; 
	bRet = GetVolumeInformation( ISNIL(1) ? NULL : (LPCTSTR) hb_parc(1) , 
			(LPTSTR) VolumeNameBuffer, 
			MAX_PATH, 
			&VolumeSerialNumber, 
			&MaximumComponentLength, 
			&FileSystemFlags, 
			(LPTSTR)FileSystemNameBuffer, 
			MAX_PATH ) ; 
if ( bRet  ) 
{ 
    if ( ISBYREF( 2 ) )  hb_storc ((char *) VolumeNameBuffer, 2 ) ; 
    if ( ISBYREF( 3 ) )  hb_stornl( (LONG)  VolumeSerialNumber, 3 ) ; 
    if ( ISBYREF( 4 ) )  hb_stornl( (LONG)  MaximumComponentLength, 4 ) ; 
    if ( ISBYREF( 5 ) )  hb_stornl( (LONG)  FileSystemFlags, 5 ) ; 
    if ( ISBYREF( 6 ) )  hb_storc ((char *) FileSystemNameBuffer, 6 ) ; 
} 
	hb_retl(bRet); 
	hb_xfree( VolumeNameBuffer ); 
	hb_xfree( FileSystemNameBuffer ); 
} 
#pragma ENDDUMP 

Re: Func C GetVolumeInformation()

Posted: Fri Jan 08, 2016 2:24 pm
by andyglezl

Re: Func C GetVolumeInformation()

Posted: Fri Jan 08, 2016 4:31 pm
by ndarz
Gracias Andy, me fijo

with the power of google translate

Thanks Andy, I notice.

Re: Func C GetVolumeInformation()

Posted: Fri Jan 08, 2016 4:34 pm
by ndarz
Igual si alguien sabe que paso con dicha función que comente.

with the power of google translate

Like if someone knows what happened to that function to comment.

Re: Func C GetVolumeInformation()

Posted: Sun Jan 10, 2016 9:18 am
by ndarz
Gracias Andy fue de mucha utilidad tu codigo.
En cuanto al otro, buscando mas a fondo en HARBOUR, lo he corregido, 2 funciones cambiaron:

Code: Select all

ISNIL()            cambio a     HB_ISNIL()
ISBYREF()       cambio a     HB_ISBYREF()