Getting debug Assertion failed messege
-
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
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
-
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
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.
-
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
-
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.
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
-
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
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); -
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
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
-
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
-
The problem, as I mentioned here, is that the
FILE*
passed tofprintf()
isNULL
. 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
-
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); -
The problem, as I mentioned here, is that the
FILE*
passed tofprintf()
isNULL
. 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
-
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.
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 ofsLogFile
.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
-
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 ofsLogFile
.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
-
I'm writing dll and using it in C# so I cant put the break point. That is main problem to trace out.
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