Island-Window, _uuidof of a COM interface

Does Island-Windows have a counterpart for C++'s __uuidof? For example, __uuidof(IUnknown)
What is the best to have a similar functionality?

guidOf(IUnknown)

2 Likes

Thank you @joseasl

Island-Windows rtl covers win32 APIs well.

But, it seems if we want to do Windows COM with Island for consuming 3rd-party COM libraries:

  • A bit of heavy-lifting is still in order, as current Island support for Win32 COM is fairly thin, especially when compared to Delphi.
  • I guess for the foreseeable near future, Island-Window COM support would continue to remain thin.
  • The users can by themselves port Delphi’s COM utility functions and classes. A lot of Delphi existing COM utility functions/classes are wrappers of MS COM API - so the porting would be straightforward and can be done easily by end users.

Here are some sample Delphi’s COM utility functions ported to Island-Window/Oxygene, for other users reference.

method CreateComObject(const aClassID: String): IUnknown;
begin
  var IID_IUnknown: rtl.GUID := guidOf(IUnknown);
  var CLSID: rtl.GUID := new RemObjects.Elements.System.Guid(aClassID); 
  OleCheck(CoCreateInstance(@CLSID, nil, DWORD(CLSCTX.CLSCTX_INPROC_SERVER or CLSCTX.CLSCTX_LOCAL_SERVER), @IID_IUnknown, (^LPVOID)(@result)));    
end;


method OleCheck(aHRESULT: HRESULT);
begin
  if not Succeeded(aHRESULT) then OleError(aHRESULT);
end;

method OleError(aErrorCode: HRESULT);
begin
  raise new EOleSysError(nil, aErrorCode, 0);
end;

method Succeeded(aHRESULT: HRESULT): Boolean;
begin
  result := aHRESULT and $80000000 = 0;
end;

method SysErrorMessage(aErrorCode: Cardinal; aModuleHandle: HLOCAL := 0): String;
begin
  var lFlags:DWORD := FORMAT_MESSAGE_FROM_SYSTEM or FORMAT_MESSAGE_IGNORE_INSERTS or FORMAT_MESSAGE_ARGUMENT_ARRAY or FORMAT_MESSAGE_ALLOCATE_BUFFER;
  if aModuleHandle <> nil then lFlags := lFlags or FORMAT_MESSAGE_FROM_HMODULE;
 
  var lpBuffer: LPWSTR;
  var lLen:DWORD := FormatMessage(lFlags, aModuleHandle, aErrorCode, 0, (LPWSTR)(@lpBuffer), 0, nil);

  try
    while (lLen > 0) and ((lpBuffer[lLen - 1] <= #32) or (lpBuffer[lLen - 1] = '.')) do begin
      dec(lLen);
    end;

    result := String.FromPChar(lpBuffer, lLen);
  finally
    LocalFree(HLOCAL(lpBuffer^));
  end;
end;
1 Like