Partager via


ptr::operator!

Opérateur pour déterminer si l'objet COM possédé est valide.

bool operator!();

Valeur de retour

true si l'objet COM possédé est valide ; false sinon.

Notes

l'objet COM possédé est valide si ce n'est pas nullptr.

Exemple

Cet exemple implémente une classe CLR qui utilise com::ptr pour encapsuler son objet d' IXMLDOMDocument de membre privé.La fonction membre d' CreateInstance utilise operator! pour déterminer si un objet document est déjà possédé, et crée une seule instance si l'objet est valide.

// 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);   
   }
}
  

Configuration requise

fichier d'en-tête<msclr \ COM \ ptr.h>

Msclr::com deEspace de noms

Voir aussi

Référence

ptr::operator bool

Autres ressources

membres PTR