convertToIID function Null safety com

Pointer<GUID> convertToIID(
  1. String strIID
)

Converts a Dart string into an IID using the IIDFromString call.

You can pass this method a brace-enclosed string, such as '{00000000-0000-0000-C000-000000000046}', and 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> convertToIID(String strIID) {
  final lpszIID = strIID.toNativeUtf16();
  final iid = calloc<GUID>();

  try {
    final hr = IIDFromString(lpszIID, iid);
    if (FAILED(hr)) {
      throw WindowsException(hr);
    }
    return iid;
  } finally {
    free(lpszIID);
  }
}