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. Windows has triggered a breakpoint in exe.......

Windows has triggered a breakpoint in exe.......

Scheduled Pinned Locked Moved C / C++ / MFC
debuggingtoolshelpquestion
12 Posts 4 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 Offline
    A Offline
    Andraw111
    wrote on last edited by
    #1

    Hi, dear all, I create a DLL that will apply calculation. class __declspec(dllexport) Class1{} class __declspec(dllexport) Class2{} class __declspec(dllexport) Utility{ static Class1* CreateCase1Obj(){ Class1* obj = new Class1(); return obj; } } Other application will use the Utility to get Class1 object as the following: Class1* obj = Utility::CreateCase1Obj(); The error happens inside CreateCase1Obj() function while call "return obj;" and browser points to dbgheap.c file. Can anybody tell me what cause this error? Thanks!

    A S 2 Replies Last reply
    0
    • A Andraw111

      Hi, dear all, I create a DLL that will apply calculation. class __declspec(dllexport) Class1{} class __declspec(dllexport) Class2{} class __declspec(dllexport) Utility{ static Class1* CreateCase1Obj(){ Class1* obj = new Class1(); return obj; } } Other application will use the Utility to get Class1 object as the following: Class1* obj = Utility::CreateCase1Obj(); The error happens inside CreateCase1Obj() function while call "return obj;" and browser points to dbgheap.c file. Can anybody tell me what cause this error? Thanks!

      A Offline
      A Offline
      Albert Holguin
      wrote on last edited by
      #2

      Probably crashing because you're attempting to create a class from code you never imported.

      A 1 Reply Last reply
      0
      • A Albert Holguin

        Probably crashing because you're attempting to create a class from code you never imported.

        A Offline
        A Offline
        Andraw111
        wrote on last edited by
        #3

        Thanks for your reply. In my project's cpp file from where I will call function from DLL, I add the following lines at the file top: __declspec(dllimport) class Class1; __declspec(dllimport) class Class2; __declspec(dllimport) class Utility; but still get the same error.

        A 1 Reply Last reply
        0
        • A Andraw111

          Thanks for your reply. In my project's cpp file from where I will call function from DLL, I add the following lines at the file top: __declspec(dllimport) class Class1; __declspec(dllimport) class Class2; __declspec(dllimport) class Utility; but still get the same error.

          A Offline
          A Offline
          Andraw111
          wrote on last edited by
          #4

          I test the program, the reason for the error is that I pass std::string as argument to Class1 constructor. Class1(std::string arg1, std::string arg2){ this.ProjDir = arg1.data(); this.ProjName = arg2.data(); } calling side: std::string dir = "....."; std::string name = "...."; Class1 obj = new Class1(dir name); I test if I call empty constructor, it's fine. What should I do now? I need to pass these value to Class1.

          L 1 Reply Last reply
          0
          • A Andraw111

            I test the program, the reason for the error is that I pass std::string as argument to Class1 constructor. Class1(std::string arg1, std::string arg2){ this.ProjDir = arg1.data(); this.ProjName = arg2.data(); } calling side: std::string dir = "....."; std::string name = "...."; Class1 obj = new Class1(dir name); I test if I call empty constructor, it's fine. What should I do now? I need to pass these value to Class1.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Try using the c_str()[^] member function to get the data from the string parameters.

            One of these days I'm going to think of a really clever signature.

            A 1 Reply Last reply
            0
            • A Andraw111

              Hi, dear all, I create a DLL that will apply calculation. class __declspec(dllexport) Class1{} class __declspec(dllexport) Class2{} class __declspec(dllexport) Utility{ static Class1* CreateCase1Obj(){ Class1* obj = new Class1(); return obj; } } Other application will use the Utility to get Class1 object as the following: Class1* obj = Utility::CreateCase1Obj(); The error happens inside CreateCase1Obj() function while call "return obj;" and browser points to dbgheap.c file. Can anybody tell me what cause this error? Thanks!

              S Offline
              S Offline
              Stephen Hewitt
              wrote on last edited by
              #6

              Looks like you're crashing because of heap corruption. The crash is almost certainly happening in the "Class1* obj = new Class1();" line (it's common for the line number to indicate the line after actual call in question), the "dbgheap.c" all but proves it.   With heap problems the actual root cause (when the heap got corrupted) and the resulting crash (in your case when the heap manager detects it) can be separated but quite some time, which makes it difficult to debug.   I'll take a wild quess at the cause however:  Looks like the new statement with allocates the object is in the DLL. How is it deleted? By a delete statement in the DLL's client? If so try moving it into the DLL where it belongs:

              void DeleteCase1Obj(Class1 *obj)
              {
                 delete obj;
              }

              Replace all deletes of this object in the client with calls to this function which is exported from the DLL.

              Steve

              1 Reply Last reply
              0
              • L Lost User

                Try using the c_str()[^] member function to get the data from the string parameters.

                One of these days I'm going to think of a really clever signature.

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

                Richard, thanks for your suggestion. Yes, if in the calling side I pass string.c_str() value string xx = "calling..."; func(xx.c_str()); and in the function definition side I define function as: func(const char* str){} everything is fine. But my project has hundreds functions, it was created in C++ 6.0, now I wish to migrate it to VS2008, if I have to modify all the function definition and modify all the places to function call, that's a big work. Is there any better way to solve this issue? Thanks!

                L 1 Reply Last reply
                0
                • A Andraw111

                  Richard, thanks for your suggestion. Yes, if in the calling side I pass string.c_str() value string xx = "calling..."; func(xx.c_str()); and in the function definition side I define function as: func(const char* str){} everything is fine. But my project has hundreds functions, it was created in C++ 6.0, now I wish to migrate it to VS2008, if I have to modify all the function definition and modify all the places to function call, that's a big work. Is there any better way to solve this issue? Thanks!

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  I do not know of any simple way other than "Find & Replace in Files" (Ctrl+Shift+H). It's a pity that you created the functions to accept char* parameters rather than string object references, then you would not have had to change in so many places. [edit] It is, of course, always possible, that the 'bug' in your code will not be fixed by these changes, but is connected to something else. Make sure that you are actually fixing the right problem before you make all these changes. [/edit]

                  One of these days I'm going to think of a really clever signature.

                  A 1 Reply Last reply
                  0
                  • L Lost User

                    I do not know of any simple way other than "Find & Replace in Files" (Ctrl+Shift+H). It's a pity that you created the functions to accept char* parameters rather than string object references, then you would not have had to change in so many places. [edit] It is, of course, always possible, that the 'bug' in your code will not be fixed by these changes, but is connected to something else. Make sure that you are actually fixing the right problem before you make all these changes. [/edit]

                    One of these days I'm going to think of a really clever signature.

                    A Offline
                    A Offline
                    Andraw111
                    wrote on last edited by
                    #9

                    I am testing to pass std::string by reference instead of std::string, it works fine. so in this case, all I need to do are modify all the function siguratures with std::string as argument, that saves a lots of time. Thanks!

                    L 1 Reply Last reply
                    0
                    • A Andraw111

                      I am testing to pass std::string by reference instead of std::string, it works fine. so in this case, all I need to do are modify all the function siguratures with std::string as argument, that saves a lots of time. Thanks!

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #10

                      I also just noticed that in one of your earlier posts you are using std::strings for string constants. This is a waste of time as you are just adding extra code to copy the constant character value into a std::string in order to pass it to some function.

                      One of these days I'm going to think of a really clever signature.

                      A 1 Reply Last reply
                      0
                      • L Lost User

                        I also just noticed that in one of your earlier posts you are using std::strings for string constants. This is a waste of time as you are just adding extra code to copy the constant character value into a std::string in order to pass it to some function.

                        One of these days I'm going to think of a really clever signature.

                        A Offline
                        A Offline
                        Andraw111
                        wrote on last edited by
                        #11

                        Yes, this issue is caused by pass std::string between EXE and DLL. When I search the solution from internet, all say that you canno pass std::string between DLLs, you'd better pass C-style character string, that's way I convert std::string to char*. Now since passing std:: string by reference can solve the issue, that's best.

                        L 1 Reply Last reply
                        0
                        • A Andraw111

                          Yes, this issue is caused by pass std::string between EXE and DLL. When I search the solution from internet, all say that you canno pass std::string between DLLs, you'd better pass C-style character string, that's way I convert std::string to char*. Now since passing std:: string by reference can solve the issue, that's best.

                          L Offline
                          L Offline
                          Lost User
                          wrote on last edited by
                          #12

                          Andraw111 wrote:

                          this issue is caused by pass std::string between EXE and DLL.

                          I'm sure it's more than just that.

                          Andraw111 wrote:

                          you canno pass std::string between DLLs

                          If that were true you would not be able to pass any objects between DLLs.

                          One of these days I'm going to think of a really clever signature.

                          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