Page 1 of 1
funcion uuid()
Posted: Sat Feb 23, 2008 12:48 am
by Vikthor
Alguien tendrá una función que genere el codigo uuid() ?
Gracias por anticipado
Posted: Sat Feb 23, 2008 1:07 am
by Vikthor
encontré este código en la red :
* Funcion que genera un GUID de 36 caracteres *
***********************************************/
function generateGUID()
{
$guidstr = "";
for ($i=1;$i<=16;$i++)
{
$b = (int)rand(0,0xff);
if ($i == 7) { $b &= 0x0f; $b |= 0x40; } // version 4 (random)
if ($i == 9) { $b &= 0x3f; $b |= 0x80; } // variant
$guidstr .= sprintf("%02s", base_convert($b,10,16));
if ($i == 4 || $i == 6 || $i == 8 || $i == 10) { $guidstr .= '-'; }
}
$guidstr=md5($_SERVER['SERVER_NAME'].$guidstr.microtime());
return substr($guidstr,0,8)."-".substr($guidstr,8,4)."-".substr($guidstr,12,4)."-".substr($guidstr,16,4)."-".substr($guidstr,20,12) ;//$guidstr;
}
Hay alguna alma caritativa
que me ayude a pasarlo a C para usarlo con xHarbour
Posted: Sat Feb 23, 2008 11:30 am
by Antonio Linares
Vikthor,
Para adaptar esa función necesitas rand() y md5() para C.
No te sería más fácil usar la función nRandom() de FWH para generar varios valores aleatorios y asi construir el GUID ? Eso es lo que hace basicamente esa función en C.
Posted: Sat Feb 23, 2008 2:09 pm
by Vikthor
Antonio :
Las funciones que mencionas en que librería estan ?
Tengo que generar registros con esa función para obtener valores cómo estos :
01b1f5f7-01a8-54de-f173-a3abae11f875
03bdf88e-bf91-8636-1a40-30240c156a0a
07b1ff1d-e655-132d-69cc-6380683099fd
0ab5b5be-26d3-862b-a588-45e9aad7b800
0aff342e-ad32-39c0-d43a-ab0614277a26
0d7be660-7e01-229a-a089-8ed1bf48c10c
13d0b448-c3dd-fdb4-b7d4-74a35b251b35
172b85da-45bc-9dbb-62e9-b1e29e493de1
17def03c-1404-3577-6d98-8278ca23db5a
17e03e65-1a4b-e395-cf8c-3ac72145fab9
Posted: Sat Feb 23, 2008 2:47 pm
by Antonio Linares
Solo necesitas nRandom( [<nRango>] ) --> n
y DecToHex( n ) --> cHex.
Ambas estan en FWH y asi puedes construir tu función desde PRG
Posted: Sat Feb 23, 2008 7:36 pm
by mmercado
Hola Tocayo:
Tal vez este link te sea de utilidad
http://www.codeproject.com/KB/string/uniquestring.aspx
Saludos
Manuel Mercado
Posted: Mon Feb 25, 2008 8:47 am
by StefanHaupt
Vikthor,
here is a sample how to create a 16bit and a 32 bit GUID.
Code: Select all
//-------------------------
// GuID generieren
// Stefan Haupt, April 2005
//-------------------------
#include "FiveWin.ch"
PROCEDURE Main ()
MsgInfo ("GuID16: "+CreateGuID16(.t.)+CRLF+"GuID32: "+CreateGuID32(.t.),"GuID")
RETURN
//------------------------------------------------------------------
// short packed GUID ( 16 byte )
//------------------------------------------------------------------
FUNCTION CreateGuID16 (lNoBracket)
LOCAL nCnt := 1, nID := 0, cID := ""
LOCAL cGuID := ""
DEFAULT lNoBracket := .F.
cID := NewGuid16 ()
FOR nCnt := 1 TO Len(cID)
nID := SubStr(cID,nCnt,1)
cGuID := cGuID + FT_Byt2Hex (nID)
NEXT
cGuid := CharRem ("h",cGuid)
cGuid := PosIns (cGuid,"-",9)
cGuid := PosIns (cGuid,"-",14)
cGuid := PosIns (cGuid,"-",19)
cGuid := PosIns (cGuid,"-",24)
IF !lNoBracket
cGuid := "{"+cGuid+"}"
ENDIF
RETURN (cGuID)
//------------------------------------------------------------------
// standard 38 byte's M$ GuID
//------------------------------------------------------------------
FUNCTION CreateGuID32 (lNoBracket)
LOCAL cGuID := NewGuid()
DEFAULT lNoBracket := .F.
IF lNoBracket
cGuid := CharRem ("{",cGuid)
cGuid := CharRem ("}",cGuid)
ENDIF
RETURN (cGuID)
// Many thanks to Valerie for his help
// and these 2 functions
#pragma BEGINDUMP
#include <windows.h>
#include "hbapi.h"
//------------------------------------------------------------------
// short packed GUID for use in may program ( 16 byte )
//------------------------------------------------------------------
HB_FUNC( NEWGUID16 )
{
GUID mguid;
if ( CoCreateGuid(&mguid) != NULL )
memset(( LPVOID ) &mguid,'?',sizeof( mguid ));
hb_retclen(( LPVOID ) &mguid,sizeof( mguid ));
}
//------------------------------------------------------------------
// standard 38 byte's M$ guid
//------------------------------------------------------------------
HB_FUNC( NEWGUID )
{
GUID guid;
char obuff[38];
memset( obuff, 0x0, 38 );
if ( CoCreateGuid(&guid) == NULL )
{
OLECHAR tmpbuff[76];
StringFromGUID2(&guid,tmpbuff,76);
WideCharToMultiByte(CP_OEMCP,0,tmpbuff,-1,obuff,38,NULL,NULL);
}
hb_retclen(obuff,38);
}
#pragma ENDDUMP
Hope it helps.
Posted: Mon Feb 25, 2008 5:08 pm
by Vikthor
Stefan :
Error: Unresolved external '_HB_FUN_FT_BYT2HEX' referenced from Error: Unresolved external '_HB_FUN_CHARREM' referenced from
Error: Unresolved external '_HB_FUN_POSINS' referenced from
I need any lib to link those functions ?
Thanks
Posted: Mon Feb 25, 2008 8:36 pm
by StefanHaupt
Vikthor,
sorry, I forgot to mention it, you have link ct.lib and libnf.lib. Both libs are included in xHarbour.
Posted: Thu Feb 28, 2008 5:58 pm
by Vikthor
Thanks Stefan.