Page 1 of 1

uuidof

Posted: Fri Jan 01, 2010 11:44 pm
by Polo
Hi,

Do you know if there is any equivalent of the function "uuidof" for Purebasic?
It is used on an interface.

Thanks !

Re: uuidof

Posted: Sat Jan 02, 2010 12:15 am
by ts-soft
I think you can use this:

Code: Select all

Procedure StringToBStr(string.s)
  Protected *Buffer = AllocateMemory(StringByteLength(string, #PB_Unicode) + 2)
  Protected bstr_string.i
  If *Buffer
    PokeS(*Buffer, string, -1, #PB_Unicode)
    bstr_string = SysAllocString_(*Buffer)
    FreeMemory(*Buffer)
  EndIf
  ProcedureReturn bstr_string
EndProcedure

Define.GUID UUID

uidstr.i = StringToBStr("{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}")
CLSIDFromString_(uidstr, @UUID)
SysFreeString_(uidstr)
Debug UUID
not tested, only to illustrate

greetings
Thomas

Re: uuidof

Posted: Sat Jan 02, 2010 12:25 am
by srod
You might also want to look at the function COMate_GetIIDFromName() from the COMatePLUS source which will search your registry for an interface's 'friendly name' (e.g. iUnknown) and, if found, will return the appropriate GUID etc.

Re: uuidof

Posted: Sat Jan 02, 2010 3:16 pm
by Polo
Thanks a lot for the quick replies, I will try what you suggested!

Re: uuidof

Posted: Sat Jan 02, 2010 5:04 pm
by Polo
ts-soft wrote:I think you can use this:

Code: Select all

Procedure StringToBStr(string.s)
  Protected *Buffer = AllocateMemory(StringByteLength(string, #PB_Unicode) + 2)
  Protected bstr_string.i
  If *Buffer
    PokeS(*Buffer, string, -1, #PB_Unicode)
    bstr_string = SysAllocString_(*Buffer)
    FreeMemory(*Buffer)
  EndIf
  ProcedureReturn bstr_string
EndProcedure

Define.GUID UUID

uidstr.i = StringToBStr("{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}")
CLSIDFromString_(uidstr, @UUID)
SysFreeString_(uidstr)
Debug UUID
not tested, only to illustrate

greetings
Thomas
After testing this was exactly what I needed, thank you Thomas!