Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Getting debug Assertion failed messege

Getting debug Assertion failed messege

Scheduled Pinned Locked Moved C / C++ / MFC
c++graphicsdebugginghelptutorial
16 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A agarunk

    As per me yes it is. Is there something I need to takecare about that??? Its just a File pointer. Its creating empty file but while coming to "fprintf" it'll throw the error. version.message is a string. I have got lots of "fprintf" statement in the module and I checked with all of them one by one its throwing the same error as above. I'm creatin .dll using ATL in VS 2005. Regards, Arun

    J Offline
    J Offline
    Jorgen Sigvardsson
    wrote on last edited by
    #5

    I agree with David's suggestion. Passing C++ as a "optional" parameter yeilds undefined behaviour. With CStrings, you can do this, and I bet Microsoft engineers did some tweaking to make that work. I don't know about std::string, but chances are that they are not crafted in such a way that they will work with printf()-like functions...

    -- 100% natural. No superstitious additives.

    A 1 Reply Last reply
    0
    • D David Crow

      agarunk wrote:

      version.message is a string.

      Then you should probably be using the c_str() method.


      "The largest fire starts but with the smallest spark." - David Crow

      "Judge not by the eye but by the heart." - Native American Proverb

      A Offline
      A Offline
      agarunk
      wrote on last edited by
      #6

      No I'm not making use of c_str(). Please let me know if it is required to take someother way to get this thing done. If possible with a sample piece of code. Thanking you Arun

      J D 2 Replies Last reply
      0
      • J Jorgen Sigvardsson

        I agree with David's suggestion. Passing C++ as a "optional" parameter yeilds undefined behaviour. With CStrings, you can do this, and I bet Microsoft engineers did some tweaking to make that work. I don't know about std::string, but chances are that they are not crafted in such a way that they will work with printf()-like functions...

        -- 100% natural. No superstitious additives.

        A Offline
        A Offline
        agarunk
        wrote on last edited by
        #7

        Yes I agree with you, but what exactly I'm supposed to do now. Please tell me if you are having some other alternatives or proper approach to tackle this. If possible with a sample piece of code. (I'm getting error in "fprintf" part of file operation though "fopen" is working properly) Thanks, Arun

        1 Reply Last reply
        0
        • A agarunk

          No I'm not making use of c_str(). Please let me know if it is required to take someother way to get this thing done. If possible with a sample piece of code. Thanking you Arun

          J Offline
          J Offline
          Jorgen Sigvardsson
          wrote on last edited by
          #8

          The %s directive makes printf() and friends expect a string pointer on the stack. If you pass an object, such as std::string, you'll give it "garbage". If you give it a pointer to the internal string buffer instead, it'll work.

          std::string str;
          const char* pInternalBuffer = str.c_str();
          printf("A string: %s\n", pInternalBuffer);

          A 1 Reply Last reply
          0
          • A agarunk

            No I'm not making use of c_str(). Please let me know if it is required to take someother way to get this thing done. If possible with a sample piece of code. Thanking you Arun

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #9

            Have you tried:

            fprintf(sLogFile, "Version : %s\n", version.message**.c_str()**);


            "The largest fire starts but with the smallest spark." - David Crow

            "Judge not by the eye but by the heart." - Native American Proverb

            A 1 Reply Last reply
            0
            • D David Crow

              Have you tried:

              fprintf(sLogFile, "Version : %s\n", version.message**.c_str()**);


              "The largest fire starts but with the smallest spark." - David Crow

              "Judge not by the eye but by the heart." - Native American Proverb

              A Offline
              A Offline
              agarunk
              wrote on last edited by
              #10

              Thanks. I tried that too but didn't work either.

              D 1 Reply Last reply
              0
              • A agarunk

                Thanks. I tried that too but didn't work either.

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #11

                The problem, as I mentioned here, is that the FILE* passed to fprintf() is NULL. That's what the assertion is telling you.


                "The largest fire starts but with the smallest spark." - David Crow

                "Judge not by the eye but by the heart." - Native American Proverb

                A 1 Reply Last reply
                0
                • J Jorgen Sigvardsson

                  The %s directive makes printf() and friends expect a string pointer on the stack. If you pass an object, such as std::string, you'll give it "garbage". If you give it a pointer to the internal string buffer instead, it'll work.

                  std::string str;
                  const char* pInternalBuffer = str.c_str();
                  printf("A string: %s\n", pInternalBuffer);

                  A Offline
                  A Offline
                  agarunk
                  wrote on last edited by
                  #12

                  Thanks. I tried it but didnt solve the problem. I refered in some other atricles and I think it might happening because of default debugging output directory. What do you think???

                  1 Reply Last reply
                  0
                  • D David Crow

                    The problem, as I mentioned here, is that the FILE* passed to fprintf() is NULL. That's what the assertion is telling you.


                    "The largest fire starts but with the smallest spark." - David Crow

                    "Judge not by the eye but by the heart." - Native American Proverb

                    A Offline
                    A Offline
                    agarunk
                    wrote on last edited by
                    #13

                    But it is creating the file in the "fopen" statement. Ok incase as you said if it is doing so then what is the solution for that. What I'm supposed to do on that case.

                    D 1 Reply Last reply
                    0
                    • A agarunk

                      But it is creating the file in the "fopen" statement. Ok incase as you said if it is doing so then what is the solution for that. What I'm supposed to do on that case.

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #14

                      agarunk wrote:

                      What I'm supposed to do on that case.

                      I'm out of ideas at this point. You might try setting a breakpoint on the fprintf() statement and verify the value of sLogFile.


                      "The largest fire starts but with the smallest spark." - David Crow

                      "Judge not by the eye but by the heart." - Native American Proverb

                      A 1 Reply Last reply
                      0
                      • D David Crow

                        agarunk wrote:

                        What I'm supposed to do on that case.

                        I'm out of ideas at this point. You might try setting a breakpoint on the fprintf() statement and verify the value of sLogFile.


                        "The largest fire starts but with the smallest spark." - David Crow

                        "Judge not by the eye but by the heart." - Native American Proverb

                        A Offline
                        A Offline
                        agarunk
                        wrote on last edited by
                        #15

                        I'm writing dll and using it in C# so I cant put the break point. That is main problem to trace out.

                        D 1 Reply Last reply
                        0
                        • A agarunk

                          I'm writing dll and using it in C# so I cant put the break point. That is main problem to trace out.

                          D Offline
                          D Offline
                          David Crow
                          wrote on last edited by
                          #16

                          At a minimum:

                          FILE *sLogFile = fopen("XMPLog.txt", "wb");
                          if (sLogFile != NULL)
                          {
                          fprintf(sLogFile, "Version : %s\n", version.message.c_str());
                          fclose(sLogFile);
                          }
                          else
                          MessageBox(...);


                          "The largest fire starts but with the smallest spark." - David Crow

                          "Judge not by the eye but by the heart." - Native American Proverb

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups