|
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.
|
|
|
|
|
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 delete d? 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 delete s of this object in the client with calls to this function which is exported from the DLL.
Steve
|
|
|
|
|
Hi, dear all,
I have a DLL file created in C++ 6.0, now move to VS2008 and get compile error.
in header file:
#define XXXPORT __declspec(dllimport)
template <class TP> class XXXPORT TPtrList
{
public:
int entries(bool deleted = false) const;
TP *operator[](int n);
const TP *operator[](int n) const;
..............
..............
}
in .cpp file
template <class TP>
inline int TPtrList<TP>::entries(bool deleted) const
{
.........
}
template <class TP>
inline TP *ABSTPtrList<tp>::operator[](int n)
{
.........}
In C++, they are fine, but in VS2008, When I compile it, I got
error C2491: 'TPtrList<TP>'::entries' : definition of dllimport function not allowed
error C2491: 'TPtrList<TP>::operator []' : definition of dllimport function not allowed
What cause this problem? Thanks!
|
|
|
|
|
This looks like you're defining the functions when doing the dll import... when all you should have is function prototypes. You probably want to define XXPORT up there to say dllexport.
|
|
|
|
|
Yes, you are right.
I just change to dllexport, then I can add function implementation to it, so can be used by other class inside this DLL.
Thanks!
|
|
|
|
|
Hi, dear all,
I create a class name Point2D to store coordinate value, with "<" and "==" two operators overloadings.
Then create a type based on it as:
typedef std::vector<Point2D*> Point2D_Vector;
Point2D_Vector PointVector;
Then add some data to PointVector.
When I loop the vector:
Point2D_Vector::iterator itr;
for (itr=PointVector.begin(); itr!=PointVector.end(); itr++)
if (itr != 0)
delete *itr;
They work fine in C++6.0, now when I try to compile it in VS2008 I got the error message in if(itr != 0) line:
error C2679: binary '!=' : no operator found which takes a right-hand operand of type 'int' (or there is no acceptable conversion)
How can I solve this issue? Thanks!
|
|
|
|
|
|
The statement itr != 0 makes no sense. Even when it compiled in VC6 it wasn't doing what it looks like you intended (to stop deleting a NULL pointer). You probably mean this:
if (*itr != 0)
Also, deleting a NULL pointer is safe in C++ (it does nothing). The check is not needed and it potentially makes the code less efficient as the compiler inserts code to check for this automatically.
Steve
|
|
|
|
|
Thanks, Chris and Steve, it can be compiled now.
|
|
|
|
|
a code to change string to uppercase using integer values within the code.
|
|
|
|
|
There are built in library and MFC functions to perform this. Please explain what you mean by "change string to uppercase using integer values"?
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Hint: There's an offset of 32 between lower and upper cased letters. For example, the ascii value (int) of lower case 'c' is 99, and the same of upper case 'C' is 67.
"Real men drive manual transmission" - Rajesh.
|
|
|
|
|
The integer difference between a lowercase char and a uppercase char when subtracted is 32.
simply subtract the lowercase by 32 to get a uppercase char.
#include <stdio.h>
#include <string.h>
int main(void)
{
char strchr[32] = "the quick fox";
int strlength=strlen(strchr);
printf("Before\n" );
printf("%s\n\n", strchr);
for (int i=0; i<strlength; i++)
{
if((strchr[i] >= 97) && (strchr[i] <= 122))
{
strchr[i] = strchr[i] -32;
}
}
printf("After\n" );
printf("%s\n\n", strchr);
return(0);
}
|
|
|
|
|
Using hexadecimal rather than decimal integer values makes the code much more readable.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
TopCoder23 wrote: char strchr[32] = "the quick fox"; I would consider a different variable name as strchr is the name of a CRT function.
TopCoder23 wrote: if((strchr[i] >= 97) && (strchr[i] <= 122)) What about:
if (islower(strchr[i]))
strchr[i] = toupper(strchr[i]);
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
|
Hi,dear all,
I have a project created using C++ 6.0. Now I need to update it to VS2008, now I have a problem when I try to open a file.
In C++ 6.0
#include <fstream.h>
ifstream INPFile(INPFileName, ios::nocreate);
In VS2008
#include <fstream>
ifstream INPFile(INPFileName, ios::nocreate);
the second line get the following error:
Error 23 error C2039: 'nocreate' : is not a member of 'std::basic_ios<_Elem,_Traits>'
Error 24 error C2065: 'nocreate' : undeclared identifier
If I change the second line to the following:
ifstream INPFile(INPFileName)
then get new error as following
error 2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private member declared in class 'std::basic_ios<_Elem,_Traits>'
How can I solve this issue?
Thanks!
|
|
|
|
|
This talks about the reason for the first error:
http://www.devx.com/tips/Tip/14544[^]
After your change however, the error about the private member doesn't make sense, you probably need to show a bit more of your code.
|
|
|
|
|
Albert, thanks for your quick reply.
My project has around 50 files, I already search all header files to check if any function pass fstream as argument, and modify them all to be passed as reference instead of as object.
I don't understand why if I use following code:
ifstream fin(OutputF, ios::in,ios::nocreate);
I got error like "C2039: 'nocreate' : is not...", but if I modify it to:
ifstream fin(OutputF, ios::in,ios::_Nocreate);
I got other kind of error messge:
"error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private.."
Thanks!
|
|
|
|
|
Wait, if you're doing an ifstream (input), why are you specifiying "no create" at all? That doesn't make sense, it's not going to get created if it can't find it. That's only even applicable at all if you're opening in read/write or write modes.
|
|
|
|
|
I do not think the nocreate option exists anymore, and it should not be necessary on an input stream. You need to use the latest definitions as described here[^].
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Thanks, Albert and Richard,
Both of you are right, yes, there is no nocreate.
I solve it by remove it, but the main reason I got the " cannot access private member ..." error is that I have some functions that pass ifstream object as value, they should be passed by reference.
Thanks again!
|
|
|
|
|
Hi,
I solve my issue posted yesterday, but today has another problem related to it.
When I migrate another small project from C++ to VS2008, I double check all the function delcaration to make sure fstream object is passed by reference or pointer, but when I compile program, I still got two error messages, they are same and the only two errors.
C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private member declared in class 'std::basic_ios<_Elem,_Traits>'
In this case how should I find where the error come from?
|
|
|
|
|
I found some functions that pass std::istream or std::istrstream by value, not by reference, is that the reason to cause the problem?
|
|
|
|
|
Yes, they also need to be passed by reference, now can be compile now.
|
|
|
|