ptr::operator!
Operátor lze zjistit vlastnictví objektu COM je neplatný.
bool operator!();
Vrácená hodnota
truePokud vlastnictví objektu COM je neplatná; false jinak.
Poznámky
Vlastnictví objektu COM je platná, pokud není nullptr.
Příklad
Tento příklad implementuje třídu CLR, která používá com::ptr jeho soukromý člen zalomení IXMLDOMDocument objektu. CreateInstance Členské funkce operator! k určení, pokud je již ve vlastnictví objektu dokumentu a vytvoří novou instanci pouze pokud objekt je neplatný.
// 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);
}
}
Požadavky
Soubor hlaviček<msclr\com\ptr.h>
Obor názvů msclr::com