所有された COM オブジェクトが無効であるかどうかを判断する演算子。
bool operator!();
戻り値
所有された COM オブジェクトが無効な場合true ; 別の方法で false 。
解説
所有された COM オブジェクトは、 nullptrでない場合は有効です。
使用例
この例では、プライベート メンバー IXMLDOMDocument オブジェクトをラップするために com::ptr を使用する CLR クラスを実装します。CreateInstance のメンバー関数は、オブジェクトが無効な場合のみドキュメント オブジェクトが既に作成したを使用して、の新しいインスタンスを作成するかどうかを確認するには、を operator! 。
// comptr_op_not.cpp
// compile with: /clr /link msxml2.lib
#include <msxml2.h>
#include <msclr\com\ptr.h>
#import <msxml3.dll> raw_interfaces_only
using namespace System;
using namespace System::Runtime::InteropServices;
using namespace msclr;
// a ref class that uses a com::ptr to contain an
// IXMLDOMDocument object
ref class XmlDocument {
public:
void CreateInstance(String^ progid) {
if (!m_ptrDoc) {
m_ptrDoc.CreateInstance(progid);
if (m_ptrDoc) {
Console::WriteLine("DOM Document created.");
}
}
}
// note that the destructor will call the com::ptr destructor
// and automatically release the reference to the COM object
private:
com::ptr<IXMLDOMDocument> m_ptrDoc;
};
// use the ref class to handle an XML DOM Document object
int main() {
try {
XmlDocument doc;
// create the instance from a progid string
doc.CreateInstance("Msxml2.DOMDocument.3.0");
}
catch (Exception^ e) {
Console::WriteLine(e);
}
}
必要条件
ヘッダー ファイル <msclr\com\ptr.h>
名前空間 msclr::com