Announcement

Collapse
No announcement yet.

Exception: "Klasse nicht vorhanden!"

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Exception: "Klasse nicht vorhanden!"

    Hallo zusammen,
    nachdem ich unter dem C++ Builder V5, update Pack 1 mit CreateProcess einen Process starte frage ich mit WaitForSingleObject ab ob der Process gestartet wurde. Nach Ablauf der Wartezeit bekomme ich die Exception: "Klasse nicht vorhanden!" Die selbe Exception erhalte ich bei WaitForInputIdle. Was mache falsch?

    Danke
    Dieter

    void __fastcall TStartAppForm::OeffneAppButtonClick(TObject *Sender)
    {

    String FullPath = "C:\\WINNT\\system32\\Notepad.exe";
    StartInfo.cb = sizeof(TStartupInfo);
    setmem(&StartInfo, sizeof(TStartupInfo), 0);

    if(CreateProcess(NULL, // Applikation-Name, bei 16Bit Anwendungen NULL
    FullPath.c_str() , // Command-Line, Applikationsname
    NULL, // Process-Attributes
    NULL, // Thread-Attributes
    false, // Creation-Handle
    CREATE_DEFAULT_ERROR_MODE | NORMAL_PRIORITY_CLASS, // Creation-Flags
    NULL, // Enviroment
    NULL, // Current Directory
    &StartInfo, // Startup Info
    &ProzessInfo // Process Information
    )==TRUE)
    {
    // if(WaitForInputIdle(ProzessInfo.hProcess, 5000) == WAIT_TIMEOUT)
    if(WaitForSingleObject(ProzessInfo.hProcess, 5000) == WAIT_TIMEOUT)
    AnzeigeException("[TStartAppForm::OeffneAppButtonClick] WaitForSingleObject");

    // Speicher wieder freigeben
    CloseHandle(ProzessInfo.hThread);
    // Speicher wieder freigeben
    CloseHandle(ProzessInfo.hProcess);
    }
    else
    {
    AnzeigeException("[TStartAppForm::OeffneAppButtonClick] CreateProcess");
    }
    }
    Mache Software wird nie fertig. Man muss sie für fertig erklären.

  • #2
    AnzeigeException dürfte fehlen
    Christian

    Comment


    • #3
      Ja stimmt, die habe ich nicht mit kopiert ist in der Software vorhanden. "AnzeigeException" gibt dann den Fehlertext: "Klasse nicht vorhanden!"
      aus.

      void __fastcall TStartAppForm::AnzeigeException(String Fnkt)
      {
      LPTSTR lpMsgBuf;

      FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
      FORMAT_MESSAGE_FROM_SYSTEM |
      FORMAT_MESSAGE_IGNORE_INSERTS,
      NULL,
      GetLastError(),
      MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
      (LPTSTR) &lpMsgBuf,
      0,
      NULL);
      Application->MessageBox((LPTSTR)lpMsgBuf, Fnkt.c_str(), MB_OK | MB_ICONINFORMATION );

      LocalFree(lpMsgBuf);
      }
      Mache Software wird nie fertig. Man muss sie für fertig erklären.

      Comment


      • #4
        Wo wird eine Instanz dieser Klasse angelegt?
        Christian

        Comment


        • #5
          Nein keine Klasse es ist nur eine Funktion innerhalb der Anwendung. Der zusammenhängende Code sieht wie nachstehend aus und ist innerhalb der Form der Anwendung. An die Funktion "AnzeigeException" übergebe ich den Caption-Text für die MessageBox und die Exception wird eindeutig durch die Funktion "WaitForSingleObject" ausgelöst.

          Aber eine private Frage: Christian kann es sein, dass wir schon mal zusammen in den UAE waren?


          void __fastcall TStartAppForm::OeffneAppButtonClick(TObject *Sender)
          {

          String FullPath = "C:\\WINNT\\system32\\Notepad.exe";
          StartInfo.cb = sizeof(TStartupInfo);
          setmem(&StartInfo, sizeof(TStartupInfo), 0);

          if(CreateProcess(NULL, // Applikation-Name, bei 16Bit Anwendungen NULL
          FullPath.c_str() , // Command-Line, Applikationsname
          NULL, // Process-Attributes
          NULL, // Thread-Attributes
          false, // Creation-Handle
          CREATE_DEFAULT_ERROR_MODE | NORMAL_PRIORITY_CLASS, // Creation-Flags
          NULL, // Enviroment
          NULL, // Current Directory
          &StartInfo, // Startup Info
          &ProzessInfo // Process Information
          )==TRUE)
          {
          // if(WaitForInputIdle(ProzessInfo.hProcess, 5000) == WAIT_TIMEOUT)
          if(WaitForSingleObject(ProzessInfo.hProcess, 5000) == WAIT_TIMEOUT)
          AnzeigeException("[TStartAppForm::OeffneAppButtonClick] WaitForSingleObject");

          // Speicher wieder freigeben
          CloseHandle(ProzessInfo.hThread);
          // Speicher wieder freigeben
          CloseHandle(ProzessInfo.hProcess);
          }
          else
          {
          AnzeigeException("[TStartAppForm::OeffneAppButtonClick] CreateProcess");
          }
          }

          void __fastcall TStartAppForm::AnzeigeException(String Fnkt)
          {
          LPTSTR lpMsgBuf;

          FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
          FORMAT_MESSAGE_FROM_SYSTEM |
          FORMAT_MESSAGE_IGNORE_INSERTS,
          NULL,
          GetLastError(),
          MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
          (LPTSTR) &lpMsgBuf,
          0,
          NULL);
          Application->MessageBox((LPTSTR)lpMsgBuf, Fnkt.c_str(), MB_OK | MB_ICONINFORMATION );

          LocalFree(lpMsgBuf);
          }
          Mache Software wird nie fertig. Man muss sie für fertig erklären.

          Comment


          • #6
            Dann wird es doch eine Zeilennummer geben in der der Fehler auftritt
            Christian

            Comment


            • #7
              Ja die gibt es:

              41 if(WaitForSingleObject(ProzessInfo.hProcess, 5000) == WAIT_TIMEOUT)
              42 AnzeigeException("[TStartAppForm::OeffneAppButtonClick] WaitForSingleObject");

              Die Exception wird in Zeile 41 ausgelöst.
              Mache Software wird nie fertig. Man muss sie für fertig erklären.

              Comment


              • #8
                Wo wird ProzessInfo angelegt?
                Christian

                Comment


                • #9
                  In der zugehörigen .h



                  //---------------------------------------------------------------------------

                  #ifndef StartApplicationH
                  #define StartApplicationH
                  //---------------------------------------------------------------------------
                  #include <Classes.hpp>
                  #include <Controls.hpp>
                  #include <StdCtrls.hpp>
                  #include <Forms.hpp>
                  //---------------------------------------------------------------------------
                  class TStartAppForm : public TForm
                  {
                  __published: // Von der IDE verwaltete Komponenten
                  TButton *OeffneAppButton;
                  TButton *CloseButton;
                  void __fastcall OeffneAppButtonClick(TObject *Sender);
                  void __fastcall CloseButtonClick(TObject *Sender);

                  private: // Anwender-Deklarationen

                  void __fastcall AnzeigeException(String Fnkt);

                  public: // Anwender-Deklarationen
                  TProcessInformation ProzessInfo;
                  TStartupInfo StartInfo;
                  __fastcall TStartAppForm(TComponent* Owner);
                  };
                  //---------------------------------------------------------------------------
                  extern PACKAGE TStartAppForm *StartAppForm;
                  //---------------------------------------------------------------------------
                  #endif
                  Mache Software wird nie fertig. Man muss sie für fertig erklären.

                  Comment


                  • #10
                    Was war/ist UAE?
                    Christian

                    Comment


                    • #11
                      Hallo guten Morgen Christian,
                      Vereinigte Arabische Emirate (VAE) oder englisch united Arabien Emerates (UAE).

                      Der Frage nach zu urteilen waren wir nicht zusammen da. Es war 1999.

                      Aber hast du oder jemand aus dem Forum eine Idee zu der Fehlermeldung?

                      Einen schönen Tag
                      Dieter

                      Mache Software wird nie fertig. Man muss sie für fertig erklären.

                      Comment


                      • #12
                        Nein, war noch nie in UEA.

                        Schlage mal vor statt der TProcessInformation PROCESS_INFORMATION zu nutzen.

                        Weiterhin debugge das Programm bis zu dieser Zeile und schaue dir alle Variablen und Klassen an, ob sie - und wie - belegt sind

                        Des weiteren folgende Verbesserungen:

                        Klassennamen werden Am Anfang groß geschrieben und dann CamelCase. Variablen und Methoden werden am Anfang klein geschrieben und dann CamelCase.

                        Deine Methode Anzeige_Exception hat einen irreführenden Namen. Es ist keine Exception und die Methode wirft keine Exception




                        Christian

                        Comment


                        • #13
                          Danke Dir das werde ich probieren.

                          Ja stimmt sie wirft keine Exception. Sie wandelt einfach den Zahlencode von GetLastError in Text um und gibt den aus. TranslateErrorCode ist sicher passender.
                          Mache Software wird nie fertig. Man muss sie für fertig erklären.

                          Comment


                          • #14
                            Wie wäre es mit

                            showErrorMessage
                            Christian

                            Comment


                            • #15
                              Hallo,
                              etwas in der Art nutze ich mit meiner "neuen" Funktion TranslateErrorCode (alt: AnzeigeException).

                              Aber es ist geschafft. Es war ein Problem mit dem Parameter CurrentDir. Nun Funktioniert es.

                              Nochmal Danke und ein schönes wochenende
                              Dieter
                              Mache Software wird nie fertig. Man muss sie für fertig erklären.

                              Comment

                              Working...
                              X