' COM via DECLARE — CoInitialize, CoCreateInstance for COM objects
#COMPILE EXE
#DIM ALL

DECLARE FUNCTION CoInitialize LIB "OLE32.DLL" (BYVAL pvReserved AS LONG) AS LONG
DECLARE FUNCTION CoUninitialize LIB "OLE32.DLL" () AS LONG
DECLARE FUNCTION CoCreateInstance LIB "OLE32.DLL" (BYREF rclsid AS LongPtr, BYVAL pUnkOuter AS LONG, BYVAL dwClsContext AS LONG, BYREF riid AS LongPtr, BYREF ppv AS LongPtr) AS LONG
DECLARE FUNCTION CLSIDFromProgID LIB "OLE32.DLL" (BYVAL lpszProgID AS ASCIIZ, BYREF lpclsid AS LongPtr) AS LONG

%CLSCTX_INPROC_SERVER = 1

FUNCTION PBMAIN() AS LONG
    LOCAL hr AS LONG
    PRINT "COM via Win32 DECLARE:"
    hr = CoInitialize(0)
    PRINT "CoInitialize result: " + STR$(hr)
    PRINT "Use CoCreateInstance to create COM objects"
    PRINT "CLASS/END CLASS in native PB syntax"
    CoUninitialize()
    FUNCTION = 0
END FUNCTION
