convertToCLSID function com

Pointer<GUID> convertToCLSID(
  1. String strCLSID,
  2. {Allocator allocator = calloc}
)

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 returned pointer when they are finished with it. A FFI Arena may be passed as a custom allocator for ease of memory management.

Implementation

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

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