|
Hi,
I have written a function in a DLL as follows
std::string Myclass::MyFunc()
{
std::string ret;
ret = "HHHHHHHHHHHHHHH"
return ret;
}
I am exporting this class and importing in client app.
What I am observing is that when I call this function from C++ client, if the number of charcters assigned to ret are less than 16 the program is working fine. But if the nuber of characters assigned to ret are 16 or greater, in client program it is giving exception while assigning the returned string to local string.
It is working in Debug mode but crashing in release mode.
Thanks in advance...
-- modified at 7:56 Friday 25th May, 2007
|
|
|
|
|
Make sure that for your executable and your dll you link to the same runtime library. And check that for both release and debug modes.
|
|
|
|
|
While debugging in release mode, the deallocate functiom from xmemory file is getting called for mor than 15 characters, while coming out of scope from function in client app.
My dll is not using MFC, but client app is using MFC lib.
Can you tell how to confirm executable and dll you link to the same runtime library?
Thanks in Advance.
|
|
|
|
|
sandeepkavade wrote: Can you tell how to confirm executable and dll you link to the same runtime library?
Depends of your IDE. For Visual Studio 2005, go in the project settings -> "C/C++" and check that the Runtime Library is the same for your dll and for your executable.
|
|
|
|
|
-- modified at 13:28 Friday 25th May, 2007
Never mind, I can't read
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Here[^] are a few cases that you should consider if your application is executing perfectly in debug mode and crashing in release mode. I hope it helps you somehow. The best way could be to debug the application in release mode. In Debug mode the variables are initialized differently than how they are done in the release mode. So you may be using an uninitialized variable that has garbage value.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Don't pass C++ objects that do memory allocation between modules. This problem is exactly the kind of thing you run into when you alloc memory in one module and free it in another. If all modules use the same version of the DLL version of the CRT, it will work, but even that isn't guaranteed to work in future releases.
|
|
|
|
|
I'm using a simple check of .is_open() to see if a file I've tried to open exists/is open, at that point I will append data to it.
But if the file doesn't exist, what is the correct way to then cause it to be created, I think it might be to do with the flags but do I just use the ofstream I already have or make a new one or?
ofstream FileDataStream;
FileDataStream.open(fileName, ofstream::out | ofstream::in);
if(FileDataStream.is_open())
{
// file exists
// Read Data
// Append Data
}
else
{
// file does not exist
// WriteHeader
FileDataStream<
|
|
|
|
|
What's the problem? ofstream [by default] creates the file specified in case it doesn't exist.
--
=====
Arman
|
|
|
|
|
the file is not being created for some reason then. If the file exists, the code on debug drops into the file exists section (.is_open is valid), but if I delete the file and step through it into the "does not exist" block (.is_open has failed), I don't see the file being created and written to.
|
|
|
|
|
FileDataStream.open(fileName, ofstream::out | ofstream::in);
aha, it shouldn't be created unless there is the flag ofstream::in. Remove this flag; it makes the ofstream to think the file exists. Moreover, you even do not need ofstream::out flag; this flag is by default.
If you want read from a file then prepare a separate ifstream object.
And a minor note, why to type ofstream::out while you can shortly do ios::out. Actually, out and in are from ios.
--
=====
Arman
|
|
|
|
|
Hi Arman, well I must be misunderstanding it then because this is my code. When i step through it
"fileName" is to a valid path, because if I make the file exist, the code drops into the file exists section. If I delete the file and rerun it, it drops into the file does not exist section and it can't have been created because nothing is being written to it. Also, if the default action of ".open" is to create it if not found, where is the empty file, and why is it even going into the "file does not exist" section of the if/else??
fstream FileDataStream;
FileDataStream.open(fileName);
if(FileDataStream.is_open())
{
// file exists
// Read Data
// Append Data
}
else
{
// file does not exist
// WriteHeader
FileDataStream<<'!'<
|
|
|
|
|
ldsdbomber wrote: FileDataStream.open(fileName);
What is default mode for the fstream::open() method? If you are unsure, specify an explicit argument.
ldsdbomber wrote: when it does not exist, it does not create anything.
Do you have permission to create files in that folder?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I can create files manually via windows explorer, so unless there is a separate security issue that only affects files created through my app I don't know why it would be a problem.
I took the modes out of the fstream as the other reply indicated that they weren't needed but it didn't work with the ::in or ::out flags specified either
I got it to do something by adding this
fstream newFile;
CFileDialog fileBrowser(FALSE,".txt",NULL,OFN_OVERWRITEPROMPT,"Geske Energy Data Files (*.dat)|*.dat|",NULL);
int ret = fileBrowser.DoModal();
newFile.open (fileBrowser.GetFileName());
// WriteHeader
newFile<<'!'<<"hjhjh"<
|
|
|
|
|
ldsdbomber wrote: I took the modes out of the fstream as the other reply indicated that they weren't needed but it didn't work with the ::in or ::out flags specified either
I've got an older version of the STL, and it shows that fstream::open() has no default mode -- a mode must be supplied. That apparently is not the case with you or you would have received a compiler error. An ostream object, however, defaults to out .
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
thanks. the problem is I want to create a new file only if it doesn't exist and I can't get that to work. Unless I am being an idiot, the flag I need is ios::nocreate and this can be ORed in with the out flag
i.e.
FileDataStream.open(fileName, ofstream::out | ios::nocreate);
but when i do this, it is still making the file even when it doesn't exist. I don't know why one flag is ofstream and the other is ios, but ofstream::nocreate didn't seem to work.
Maybe I am just getting in a pickle with this, but I couldn't find a useful example that I could follow along, surely "open file for appending, unless it's not there in which case make a new one and write to it" must be a very commonly done thing!
|
|
|
|
|
Hopefully a simple question.
At design time what are the units of the measurements at the bottom left of the screen? Basically at present I want a dialog that fills the entire width of the screen (1600x1200), I can set up and populate this at runtime but would prefer to do it at design time.
cheers,
Andy
|
|
|
|
|
I assume you are talking about DLU ( Dialog Logical Unit ).
google about them.
|
|
|
|
|
Hope I understood your question
Do you need to Width and height of the screen does GetSystemMetrics(SM_CXSCREEN/SM_CYSCREEN); your answer?
|
|
|
|
|
open your dialog in resource editor and check for property "maximize"
|
|
|
|
|
mcsherry wrote: Basically I want a dialog that fills the entire width of the screen (1600x1200), I can set up and populate this at runtime but would prefer to do it at design time.
This is almost assuredly going to fail. If you want a full-screen dialog, do it at runtime. Then it will work on any system, at any resolution, using any font. Otherwise, the only system that it is guaranteed to work on is the one you designed it on.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
hello!!!
when i protect file ....the preview of a file should be displayed ...means
file should be played or displayed in a rectangle displayed on window while protecting
|
|
|
|
|
What do you mean by protecting and what do you mean by displaying the file ? And what do you mean by preview ?
Which kind of files ?
|
|
|
|
|
Ahmm... but here is there no one with telepathy??? :P
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
|
|
|
|
|
Nelek wrote: Ahmm... but here is there no one with telepathy???
Yes, but not on days that end in 'y'.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|