Create GUID from Harbour

Post Reply
User avatar
don lowenstein
Posts: 196
Joined: Mon Oct 17, 2005 9:09 pm
Contact:

Create GUID from Harbour

Post by don lowenstein »

Does anyone know how to create a GUID from Harbour?
Don Lowenstein
www.laapc.com
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: Create GUID from Harbour

Post by Enrico Maria Giordano »

Don,
don lowenstein wrote:Does anyone know how to create a GUID from Harbour?

Code: Select all

#include "Fivewin.ch"


FUNCTION MAIN()

    ? CREATEOBJECT( "Scriptlet.TypeLib" ):Guid

    RETURN NIL
EMG
User avatar
carlos vargas
Posts: 1421
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: Create GUID from Harbour

Post by carlos vargas »

Code: Select all

FUNCTION CreateGuID32( lNoBracket )
   LOCAL cGuID := NewGuid()

   DEFAULT lNoBracket := .F.

   IF lNoBracket
      cGuid := CharRem ("{", cGuid )
      cGuid := CharRem ("}", cGuid )
   ENDIF

RETURN ( cGuID )

/*-------------------------------------------------------------------------------------------------*/

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 + DecToHex( nID )
   NEXT

   cGuid := CharRem ( "h", cGuid )
   cGuid := PosIns( cGuid, "-", 09 )
   cGuid := PosIns( cGuid, "-", 14 )
   cGuid := PosIns( cGuid, "-", 19 )
   cGuid := PosIns( cGuid, "-", 24 )

   IF !lNoBracket
      cGuid := "{" + cGuid + "}"
   ENDIF

RETURN ( cGuID )

#pragma BEGINDUMP

/*llamada a encabezados de api de xharbour y windows SDK*/
#include "hbapi.h"
#include "hbapiitm.h"
#include "hbapierr.h"

#include "shlobj.h"
#include "windows.h"

/*funcion wrapper para obtener una cadena GUID de 16 bits*/
HB_FUNC( NEWGUID16 )
{
   GUID mguid;

   if( !CoCreateGuid(&mguid) )
   {
      memset( ( LPVOID ) &mguid,'?',sizeof( mguid ));
   }

   hb_retclen( (char *) &mguid,sizeof( mguid ) );
}

/*-------------------------------------------------------------------------------------------------*/
/*funcion wrapper para obtener una cadena GUID de 32 bits*/
HB_FUNC( NEWGUID )
{
   GUID guid;
   char obuff[38];
   memset( obuff, 0x0, 38 );

   if( CoCreateGuid( &guid ) )
   {
      OLECHAR tmpbuff[ 76 ];

      StringFromGUID2( &guid, tmpbuff, 76 );
      WideCharToMultiByte( CP_OEMCP, 0, tmpbuff, -1, obuff, 38, NULL, NULL );
   }

   hb_retclen( obuff, 38 );
}
#pragma ENDDUMP

 
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
manuelcalerosolis
Posts: 149
Joined: Mon Oct 10, 2005 9:30 am
Location: Huelva - Spain

Re: Create GUID from Harbour

Post by manuelcalerosolis »

Carlos,

Intento usar su función de generación de GUID de 32 bits pero me devuelve una cadena vacía.

Alguna idea?

Saludos.
User avatar
rhlawek
Posts: 165
Joined: Sun Jul 22, 2012 7:01 pm

Re: Create GUID from Harbour

Post by rhlawek »

In the hbwin contrib library harbour has the function win_uuidcreatestring()
User avatar
manuelcalerosolis
Posts: 149
Joined: Mon Oct 10, 2005 9:30 am
Location: Huelva - Spain

Re: Create GUID from Harbour

Post by manuelcalerosolis »

Rhlawek thanks.
Post Reply