Windows has triggered a breakpoint in exe.......
-
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!
-
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!
Probably crashing because you're attempting to create a class from code you never imported.
-
Probably crashing because you're attempting to create a class from code you never imported.
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.
-
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.
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.
-
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.
-
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!
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 thenew
statement with allocates the object is in the DLL. How is itdelete
d? By adelete
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
delete
s of this object in the client with calls to this function which is exported from the DLL.Steve
-
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!
-
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!
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 thanstring
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.
-
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 thanstring
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.
-
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!
I also just noticed that in one of your earlier posts you are using
std::string
s for string constants. This is a waste of time as you are just adding extra code to copy the constant character value into astd::string
in order to pass it to some function.One of these days I'm going to think of a really clever signature.
-
I also just noticed that in one of your earlier posts you are using
std::string
s for string constants. This is a waste of time as you are just adding extra code to copy the constant character value into astd::string
in order to pass it to some function.One of these days I'm going to think of a really clever signature.
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.
-
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.
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.