SaveAs function (and why I think it should be called SaveCopyAs)
|Top Previous Next|
Be careful with this function. It will accept a wchar_t but will not work unless the wchar_t is wrapped inside a CComBSTR type:
hRes = pPartDoc->SaveAs (CComBSTR(L"C:\\CHS_LHS_COLL\\This.ipt"),VARIANT_TRUE) ;
ShowCOMError(hRes,L"CCollettore::CreateCollectorMainTubePart, save failed.");
return (false) ;
That last parameter is:
Here is another example with an assembly document:
CComQIPtr<AssemblyDocument> pAssemblyDoc ;
...init pAssemblyDoc ...
CString csFullAssemblyName (L"C:\\YOUR_TEST\\Test_Assembly.iam") ;
pAssemblyDoc->SaveAs (CComBSTR(csFullAssemblyName),VARIANT_TRUE) ;
Gotcha: SaveAs will save to a copy and not change the name of the document. So inside your program you'll still have the original. If you want operate on the copy you'll have to read it in again.
If you want to save the current in memory document with a different name you can do something like this:
// In this case we just change the name and save it without closing...
CComBSTR bstrFullFileName(m_csAssemblyFullFileName); // Convert from CString to BSTR
pAssemblyDoc->PutFullFileName(bstrFullFileName.m_str); // Set the name (full file name ofthe document)
pAssemblyDoc->Save(); // Save it with the new name
Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)