FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour funcion uuid()
Posts: 298
Joined: Fri Oct 07, 2005 05:20 AM
funcion uuid()
Posted: Sat Feb 23, 2008 12:48 AM

Alguien tendr谩 una funci贸n que genere el codigo uuid() ?

Gracias por anticipado

Vikthor
Posts: 298
Joined: Fri Oct 07, 2005 05:20 AM
funcion uuid()
Posted: Sat Feb 23, 2008 01:07 AM

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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
funcion uuid()
Posted: Sat Feb 23, 2008 11:30 AM

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
Posts: 298
Joined: Fri Oct 07, 2005 05:20 AM
funcion uuid()
Posted: Sat Feb 23, 2008 02:09 PM

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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
funcion uuid()
Posted: Sat Feb 23, 2008 02:47 PM

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
Posts: 782
Joined: Wed Dec 19, 2007 07:50 AM
funcion uuid()
Posted: Sat Feb 23, 2008 07:36 PM

Hola Tocayo:

Tal vez este link te sea de utilidad

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

Saludos

Manuel Mercado

manuelmercado at prodigy dot net dot mx
Posts: 824
Joined: Thu Oct 13, 2005 07:39 AM
funcion uuid()
Posted: Mon Feb 25, 2008 08:47 AM
Vikthor,

here is a sample how to create a 16bit and a 32 bit GUID.

//-------------------------
// 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
Posts: 298
Joined: Fri Oct 07, 2005 05:20 AM
funcion uuid()
Posted: Mon Feb 25, 2008 05:08 PM

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
Posts: 824
Joined: Thu Oct 13, 2005 07:39 AM
funcion uuid()
Posted: Mon Feb 25, 2008 08:36 PM

Vikthor,

sorry, I forgot to mention it, you have link ct.lib and libnf.lib. Both libs are included in xHarbour.

kind regards

Stefan
Posts: 298
Joined: Fri Oct 07, 2005 05:20 AM
funcion uuid()
Posted: Thu Feb 28, 2008 05:58 PM

Thanks Stefan.

Vikthor

Continue the discussion