funcion uuid()

Post Reply
User avatar
Vikthor
Posts: 271
Joined: Fri Oct 07, 2005 5:20 am
Location: México

funcion uuid()

Post by Vikthor »

Alguien tendrá una función que genere el codigo uuid() ?

Gracias por anticipado
Vikthor
User avatar
Vikthor
Posts: 271
Joined: Fri Oct 07, 2005 5:20 am
Location: México

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

Post 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.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Vikthor
Posts: 271
Joined: Fri Oct 07, 2005 5:20 am
Location: México

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

Post 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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
mmercado
Posts: 782
Joined: Wed Dec 19, 2007 7:50 am
Location: Salamanca, Gto., México

Post by mmercado »

Hola Tocayo:

Tal vez este link te sea de utilidad

http://www.codeproject.com/KB/string/uniquestring.aspx

Saludos

Manuel Mercado
StefanHaupt
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Post 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.
kind regards
Stefan
User avatar
Vikthor
Posts: 271
Joined: Fri Oct 07, 2005 5:20 am
Location: México

Post 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
Vikthor
StefanHaupt
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Post by StefanHaupt »

Vikthor,

sorry, I forgot to mention it, you have link ct.lib and libnf.lib. Both libs are included in xHarbour.
kind regards
Stefan
User avatar
Vikthor
Posts: 271
Joined: Fri Oct 07, 2005 5:20 am
Location: México

Post by Vikthor »

Thanks Stefan.
Vikthor
Post Reply