convertToCLSID function Null safety com

Pointer<GUID> convertToCLSID(
  1. String strCLSID
)

Converts a Dart string into an CLSID using the CLSIDFromString call.

You can pass this method one of two things: a brace-enclosed string, such as '{00000000-0000-0000-C000-000000000046}', or a ProgID, such as 'Excel.Application'. If you pass a ProgID, it will look up the CLSID associated with it. In either case, it will return a pointer to a GUID struct that matches the string.

It is the caller's responsibility to deallocate the pointer when they are finished with it.

Implementation

Pointer<GUID> convertToCLSID(String strCLSID) {
  final lpszCLSID = strCLSID.toNativeUtf16();
  final clsid = calloc<GUID>();

  try {
    final hr = CLSIDFromString(lpszCLSID, clsid);
    if (FAILED(hr)) {
      throw WindowsException(hr);
    }
    return clsid;
  } finally {
    free(lpszCLSID);
  }
}