Data Statement Support for GUID's and CLSID's

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
akj
Enthusiast
Enthusiast
Posts: 668
Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham

Data Statement Support for GUID's and CLSID's

Post by akj »

Please add a new Data statement type so that

Code: Select all

DataSection 
Data.l $332C4425 
Data.w $26CB,$11D0 
Data.b $B4,$83,$00,$C0,$4F,$D9,$01,$19
EndDataSection
can be shortened to:

Code: Select all

DataSection
Data.g {332C4425-26CB-11D0-B483-00C04FD90119}
EndDataSection
and/or to:

Code: Select all

DataSection
Data.g 332C4425-26CB-11D0-B483-00C04FD90119
EndDataSection
Anthony Jordan
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post by Rescator »

Actually a "virtual" function to do that would be much better as you could then use it sort of directly when using API calls as well.
Like: SomeApiCallHere_(GUID("{332C4425-26CB-11D0-B483-00C04FD90119}"))
GUID() basically turns the string into 16byte binary and returns a pointer.

Or something similar to that.

Or even a

#SomeGUID=GUID("{332C4425-26CB-11D0-B483-00C04FD90119}")

So you could do:
SomeApiCallHere_(#SomeGUID) ;basically a pointer to the 16byte data.

Or even maybe:

Define someguid.guid
someguid=GUID("{332C4425-26CB-11D0-B483-00C04FD90119}")

So you could do:
SomeApiCallHere_(someguid) ;basically someguid would be a pointer in this case I guess.

Question is, how common is GUID's on Linux or Mac?
And if it's only used on Windows is it worth the effort adding it?

http://en.wikipedia.org/wiki/Globally_U ... [quote]The term GUID usually refers to Microsoft's implementation of the Universally Unique Identifier (UUID) standard; however, many other pieces of software use the term GUID including Oracle Database, dBase and Novell eDirectory. The GUID is also the basis of the GUID Partition Table, Intel's replacement for Master Boot Records under EFI.[/quote]

Edit: more info
http://en.wikipedia.org/wiki/Universall ... Identifier
A Universally Unique Identifier is an identifier standard used in software construction, standardized by the Open Software Foundation (OSF) as part of the Distributed Computing Environment (DCE).
Even Atom and some RSS feeds use them.
So maybe some UUID support is warranted?
User avatar
helpy
Enthusiast
Enthusiast
Posts: 552
Joined: Sat Jun 28, 2003 12:01 am

Re: Data Statement Support for GUID's and CLSID's

Post by helpy »

akj wrote:Please add a new Data statement type so that

Code: Select all

DataSection 
Data.l $332C4425 
Data.w $26CB,$11D0 
Data.b $B4,$83,$00,$C0,$4F,$D9,$01,$19
EndDataSection
can be shortened to...[/code]
You could use a macro:

Code: Select all

Macro GUID(__name, __l, __w1, __w2, __b1, __b2, __b3, __b4, __b5, __b6, __b7, __b8)
DataSection
__name:
  Data.l $__l
  Data.w $__w1, $__w2
  Data.b $__b1, $__b2, $__b3, $__b4, $__b5, $__b6, $__b7, $__b8
EndDataSection
EndMacro

GUID(CLSID_Test,332C4425,26CB,11D0,B4,83,00,C0,4F,D9,01,19)
Windows 10 / Windows 7
PB Last Final / Last Beta Testing
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Data Statement Support for GUID's and CLSID's

Post by PB »

> You could use a macro

True, but I'm guessing akj wants to be able to copy-and-paste the GUID
into his code, because they're such a hassle to type manually, and a macro
doesn't help because it still requires manual typing of each component.

Alternatively, akj could write an add-in tool that takes the GUID and puts
it into 3 data statements automatically for him, and then auto-types it into
the editor, or puts it in the clipboard. ;)

[Edit] Had the wrong user name in my post.
Last edited by PB on Tue Aug 07, 2007 11:52 am, edited 1 time in total.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

Many of guid, clsid, iid can you simple import:

Code: Select all

Import "uuid.lib"
  CLSID_TaskbarList
  IID_ITaskbarList
EndImport

Procedure HideFromTaskBar(hWnd.l, Flag.l)
  Protected TBL.ITaskbarList

  CoInitialize_(0)
  If CoCreateInstance_(@CLSID_TaskBarList, 0, 1, @IID_ITaskBarList, @TBL) = #S_OK
    TBL\HrInit()
    If Flag
      TBL\DeleteTab(hWnd)
    Else
      TBL\AddTab(hWnd)
    EndIf
    TBL\Release()
  EndIf
  CoUninitialize_()

EndProcedure

; DataSection
;   CLSID_TaskBarList:
;   Data.l $56FDF344
;   Data.w $FD6D, $11D0
;   Data.b $95, $8A, $00, $60, $97, $C9, $A0, $90
;   IID_ITaskBarList:
;   Data.l $56FDF342
;   Data.w $FD6D, $11D0
;   Data.b $95, $8A, $00, $60, $97, $C9, $A0, $90
; EndDataSection

If OpenWindow(0, #PB_Ignore, #PB_Ignore, 640, 480, "test")
  HideFromTaskBar(WindowID(0), #True)
  While WaitWindowEvent() <> 16 : Wend 
EndIf
Last edited by ts-soft on Tue Aug 07, 2007 9:11 am, edited 1 time in total.
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

ts-soft wrote:Many of guid, clsid, iid can you simple import:

Code: Select all

Import "uuid.lib"
  CLSID_TaskbarList
  IID_ITaskbarList
EndImport
whaoo that's great tip. i didn't know that. thanks you ts-soft.
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

Here an importfile with over 3000 imports of CLSID, GUID and IID
It's autogenerated but should work

http://ts-soft.eu/dl/GUID_CLID_IID_Import.zip
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

I would not include the whole list all the time, as then all the imported GUIDs will
get linked even if not used in the code. (just check the exe size,
its about 50k larger with the full list compared to a single import)

A nice little macro can be helpful here:

Code: Select all

Macro ImportGUID(name)
  CompilerIf Defined(name, #PB_Variable) = 0
    Import "uuid.lib"
      name
    EndImport
  CompilerEndIf
EndMacro

ImportGUID(IID_IXMLElementCollection)
x = @IID_IXMLElementCollection
With the compilerif, even multiple use with the same name is no error.

To further the number of possibilities, here are two ways from me to define
such values (in case one is not contained in the above list):

There is my GUIDViewer tool that exist since a while that has all the GUIDs from
the MS headers and generates the PB datasections:
http://freak.purearea.net/tools/GuidViewer.zip

My prefered way however is included in my COM Framework (here: http://freak.purearea.net/tools/ComFramework.zip)
It includes a resident called "GuidList.res", which contains a macro to
automatically define the GUIDs from the GUIDViewer tool.
There you can just do this and it automatically inserts the needed datasection:

Code: Select all

DefineKnownGuid(IID_IXMLElementCollection)
x = ?IID_IXMLElementCollection
So... do you still think a spechial compiler feature is needed for this ? ;)
quidquid Latine dictum sit altum videtur
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

very nice macro, thanks
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Post Reply