title: Is there a technical reason why it would be better for the COM DLL to delete the passed in temporary JSON when it is finished with it?
body: <h2>Context</h2>
  <ol>
  <li><p>My parent MFC project creates a JSON file:</p>
  <pre><code>CImportFromCLMExplorerDlg::CreateMSATranslationsJson(strTempJson);
  </code></pre>
  </li>
  <li><p>This temporary file is passed into a C# COM DLL as a parameter for it to use:</p>
  <pre><code>theApp.MSAToolsInterface().ImportHistoryFromCLMExplorer(
                       theApp.GetLanguageCode(dlgImportCLM.GetLanguageToImport()),
                       dlgImportCLM.GetCalendarDBPath(),
                       theApp.GetAssignHistoryXMLPath(),
                       strTempJson);
  </code></pre>
  </li>
  <li><p>Finally, I delete the temporary file after the above COM DLL method returns:</p>
  <pre><code>::DeleteFile(strTempJson);
  </code></pre>
  </li>
  </ol>
  <h2>My question</h2>
  <p>It is technically a better approach to get the COM DLL to delete this file once it has finished using it? Or is it perfectly fine (it appears to be) to delete it after in the parent project?</p>
  <p>I am not asking for opinions but asking if there is technical reason why it would be better for the COM DLL to delete the passed in temporary JSON when it is finished with it.</p>
  <h2>The JSON File</h2>
  <p>The comments allude to the possibility of using an <code>ISteam</code> and not passing a literal file. At the moment I am creating the JSON file like this:</p>
  <pre><code>bool CImportFromCLMExplorerDlg::CreateMSATranslationsJson(const CString strPathJson)
  {
      CkString strOut, strValue;
      CkJsonObject json;
      bool success;
  
      LanguageMSA eLang = theApp.GetProgramLanguage();
  
      // Note: The methods return false if &quot;out of memory&quot;
  
      strValue.setStringU(SMMETHOD3(eLang, IDS_CMB_METHOD_BIBLE_READING));
      success = json.AddStringAt(-1, &quot;BibleReading&quot;, strValue);
      strValue.setStringU(SMMETHOD3(eLang, IDS_STR_HISTORY_BIBLE_READING_MAIN));
      success = json.AddStringAt(-1, &quot;BibleReadingMain&quot;, strValue);
      strValue.setStringU(SMMETHOD3(eLang, IDS_STR_HISTORY_BIBLE_READING_AUX));
      success = json.AddStringAt(-1, &quot;BibleReadingAux&quot;, strValue);
      strValue.setStringU(SMMETHOD3(eLang, IDS_CMB_METHOD_INITIAL_CALL));
      success = json.AddStringAt(-1, &quot;InitialCall&quot;, strValue);
      strValue.setStringU(SMMETHOD3(eLang, IDS_STR_HISTORY_INITIAL_CALL_MAIN));
      success = json.AddStringAt(-1, &quot;InitialCallMain&quot;, strValue);
      strValue.setStringU(SMMETHOD3(eLang, IDS_STR_HISTORY_INITIAL_CALL_AUX));
      success = json.AddStringAt(-1, &quot;InitialCallAux&quot;, strValue);
      strValue.setStringU(SMMETHOD3(eLang, IDS_CMB_METHOD_RETURN_VISIT));
      success = json.AddStringAt(-1, &quot;ReturnVisit&quot;, strValue);
      strValue.setStringU(SMMETHOD3(eLang, IDS_STR_HISTORY_RETURN_MAIN));
      success = json.AddStringAt(-1, &quot;ReturnVisitMain&quot;, strValue);
      strValue.setStringU(SMMETHOD3(eLang, IDS_STR_HISTORY_RETURN_AUX));
      success = json.AddStringAt(-1, &quot;ReturnVisitAux&quot;, strValue);
      strValue.setStringU(SMMETHOD3(eLang, IDS_CMB_METHOD_BIBLE_STUDY));
      success = json.AddStringAt(-1, &quot;BibleStudy&quot;, strValue);
      strValue.setStringU(SMMETHOD3(eLang, IDS_STR_HISTORY_STUDY_MAIN));
      success = json.AddStringAt(-1, &quot;BibleStudyMain&quot;, strValue);
      strValue.setStringU(SMMETHOD3(eLang, IDS_STR_HISTORY_STUDY_AUX));
      success = json.AddStringAt(-1, &quot;BibleStudyAux&quot;, strValue);
      strValue.setStringU(SMMETHOD3(eLang, IDS_CMB_METHOD_TALK));
      success = json.AddStringAt(-1, &quot;Talk&quot;, strValue);
      strValue.setStringU(SMMETHOD3(eLang, IDS_STR_HISTORY_TALK_MAIN));
      success = json.AddStringAt(-1, &quot;TalkMain&quot;, strValue);
      strValue.setStringU(SMMETHOD3(eLang, IDS_STR_HISTORY_TALK_AUX));
      success = json.AddStringAt(-1, &quot;TalkAux&quot;, strValue);
      strValue.setStringU(SMMETHOD3(eLang, IDS_STR_HISTORY_ASSISTANT));
      success = json.AddStringAt(-1, &quot;Assistant&quot;, strValue);
      strValue.setStringU(SMMETHOD3(eLang, IDS_CMB_METHOD_QA));
      success = json.AddStringAt(-1, &quot;QuestionsAndAnswers&quot;, strValue);
      strValue.setStringU(SMMETHOD3(eLang, IDS_CMB_METHOD_DISC_VIDEO));
      success = json.AddStringAt(-1, &quot;DiscussionWithVideo&quot;, strValue);
      success = json.AddStringAt(-1, &quot;SampleConversation&quot;, &quot;Sample Conversation&quot;);
      strValue.setStringU(SMMETHOD3(eLang, IDS_CMB_METHOD_INITIAL_CALL_VIDEO));
      success = json.AddStringAt(-1, &quot;InitialCallVideo&quot;, strValue);
      strValue.setStringU(SMMETHOD3(eLang, IDS_CMB_METHOD_RETURN_VISIT_VIDEO));
      success = json.AddStringAt(-1, &quot;ReturnVisitVideo&quot;, strValue);
      strValue.setStringU(SMMETHOD3(eLang, IDS_CMB_METHOD_VIDEO));
      success = json.AddStringAt(-1, &quot;Video&quot;, strValue);
      strValue.setStringU(SMMETHOD3(eLang, IDS_STR_THEME_PRESENTATIONS));
      success = json.AddStringAt(-1, &quot;Presentations&quot;, strValue);
      strValue.setStringU(SMMETHOD3(eLang, IDS_STR_THEME_SPIRITUAL_GEMS));
      success = json.AddStringAt(-1, &quot;SpiritualGems&quot;, strValue);
  
  
      json.put_EmitCompact(false);
      strOut.append(json.emit());
      strOut.append(&quot;\r\n&quot;);
      
      CkString strPathJsonEx;
      strPathJsonEx.setStringU(strPathJson);
      return strOut.saveToFile(strPathJsonEx, &quot;utf-8&quot;);
  }
  </code></pre>
  <p>It uses the <a href="https://www.chilkatsoft.com/refdoc/vcCkJsonObjectRef.html" rel="nofollow noreferrer"><code>CkJsonObject</code></a> and <a href="https://www.chilkatsoft.com/refdoc/vcCkStringRef.html#method138" rel="nofollow noreferrer"><code>CkString</code></a> classes. I am not sure if it is possible to turn that into an object that can be passed to the DLL. For the record this is how I read in the JSON in the COM DLL at the moment:</p>
  <pre><code>private MSATranslations GetMSATranslations(string strPath)
  {
      using (var reader = new StreamReader(strPath, Encoding.UTF8))
          return JsonConvert.DeserializeObject&lt;MSATranslations&gt;(reader.ReadToEnd());
  }
  </code></pre>