don lowenstein wrote:Does anyone know how to create a GUID from Harbour?
#include "Fivewin.ch"
FUNCTION MAIN()
? CREATEOBJECT( "Scriptlet.TypeLib" ):Guid
RETURN NIL
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
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: Google [Bot] and 109 guests