Main Menu

GUID's

Started by Richard Kelly, May 13, 2026, 07:10:48 AM

Previous topic - Next topic

Richard Kelly

I had some old code below for creating guid's when I needed them. Is there something in Afx that is equivalent?

#Include once "windows.bi"
#Include once "win/uuids.bi"
#Include once "win/ole2.bi"

Dim guid As GUID
Dim wstrGUID As LPOLESTR
Dim strGUID As ZString * 260

    CoCreateGuid (@guid)
    If(StringFromCLSID (@guid, @wstrGUID) = S_OK) THEN
       WideCharToMultiByte (CP_ACP, 0, Cast(WString Ptr,wstrGUID), -1, strGUID, MAX_PATH, NULL, NULL)
        Print strGUID
     EndIf
    CoTaskMemFree(@wstrGUID)

Paul Squires

Check out AfxCOM.inc

PRIVATE FUNCTION AfxGuid (BYVAL pwszGuidText AS WSTRING PTR = NULL) AS GUID
PRIVATE FUNCTION AfxGuidText OVERLOAD (BYVAL classID AS CLSID PTR) AS STRING
PRIVATE FUNCTION AfxGuidText OVERLOAD (BYVAL classID AS CLSID) AS STRING
PRIVATE FUNCTION AfxGuidText OVERLOAD (BYVAL riid AS REFIID) AS STRING


Paul Squires
PlanetSquires Software

Richard Kelly

I knew Jose had something somewhere and, while I looked in a lot of Afx includes, I didn't look in AfxCOM.

The code below works perfectly.

DIM uGUID AS GUID
uGUID = AfxGuid()
print AfxGuidText(@uGUID)