|
Hi,
I want to append a line to file i tried like this:
CString strNewWord (_T(" Test line to write"));
CStdioFile file;
file.Open(strSystemPath,CFile::modeWrite|CFile::modeNoTruncate,NULL);
file.SeekToEnd();
CString strWriteData("\\n ");
strWriteData+=strNewWord;
file.WriteString(strWriteData);
file.Close();
this code appends data but in single line (assume no compile time errors):
\n Test line to write\n Test line to write\n Test line to write
I want like this:
Test line to write
Test line to write
Test line to write
|
|
|
|
|
Looking at the documentation[^](gasp), it says "Any newline character in lpsz is written to the file as a carriage return–linefeed pair".
I can never remember whether \n or \r is a newline character, and which is linefeed - so try either single stepping into the WriteString command and looking, or guess and try \r .
Good luck,
Iain.
Codeproject MVP for C++, I can't believe it's for my lounge posts...
|
|
|
|
|
Iain Clarke wrote: I can never remember whether \n or \r is a newline character
On windows none of them (the sequence \r\n is newline), see, for instance http://en.wikipedia.org/wiki/Newline[^].
I suppose that 'any newline' means \r or \n or \r\n (but I didn't make a test).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
That's why I'd step in and get an authoriative answer! I don't trust me either.
Iain.
Codeproject MVP for C++, I can't believe it's for my lounge posts...
|
|
|
|
|
Please don't trust me: from the same article:
To facilitate the creation of portable programs, programming languages provide some abstractions to deal with the different types of newline sequences used in different environments.
The C programming language provides the escape sequences '\n' (newline) and '\r' (carriage return). However, these are not required to be equivalent to the ASCII LF and CR control characters. The C standard only guarantees two things:
1. Each of these escape sequences maps to a unique implementation-defined number that can be stored in a single char value.
2. When writing a file in text mode, '\n' is transparently translated to the native newline sequence used by the system, which may be longer than one character. (Note that a C implementation is allowed not to store newline characters in files. For example, the lines of a text file could be stored as rows of a SQL table or as fixed-length records.) When reading in text mode, the native newline sequence is translated back to '\n'. In binary mode, the second mode of I/O supported by the C library, no translation is performed, and the internal representation of any escape sequence is output directly.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
crazy_sam wrote: CString strWriteData("\\n ");
....
\n Test line to write\n Test line to write\n Test line to write
Of course, it does exactly what you told it to do....
Hint: double backslashes.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Hi all,
In my vc++ application I am performing some operations using the Registry functionality but in Vista , registry virtualisation is coming in to picture and is creating the keys in virtual store instead of the path which i gave.I have gone through some of the material on this topic and found that if the user is not an admin then this will happen.But for my laptop I am holding the admin previlages then how come I am not able to create the keys in the correct location.
Thanks in Advance.....
|
|
|
|
|
In Vista, all programs run with low privileges by default even if the user has admin privileges. You have to elevate it to run with admin privilege by right clicking on the EXE and selecting "Run as Administrator".
«_Superman_»
|
|
|
|
|
Thats looks fine.
But how can I do that programtically coz when I deliver my product to the customer it has to be done implicitly, we can ask the user/customer to run in using the context menu(using right click)...
Do we have any other approach of doing this programatically?
|
|
|
|
|
You can specify the required privilege in the application manifest file which is an xml file.
Please check some documentation on how it is done.
«_Superman_»
|
|
|
|
|
|
Hi everyone,
Iam tryingto create a new dll in win32.
I am very new to vc++ environment. Please help me to test the application. I want both th dll and a test application in the same workspace so that I dont have to copy past the output dll everytime I update the dll project.
I have created a win32 dll. And I have added a new mfc(exe) project to the workspace to test my dll. I have given the output filename path of the dll to the mfc project.
is all my setting correct?
Can I write a small printf statement in the dllmain function to test my dll by running it (running the dll project?).
Thanks in advance
I am a learner Always
|
|
|
|
|
himangshuS wrote: I have given the output filename path of the dll to the mfc project.
Or you can set the working folder of exe project as the dll folder, to avoid dll copy.
himangshuS wrote: Can I write a small printf statement
printf is a console function. So AFAIK, you need the exe as a console app. If it is window/dialog app, then you can use
::MessageBox( 0, "My message", "From my dll", MB_SYSTEMMODAL );
himangshuS wrote: test my dll by running it (running the dll project?).
Yes, you can set the active project as dll and set the "executable for debug" as the exe. Also you can set the project dependency so that building of projects will be easier.
- ns ami -
|
|
|
|
|
Thanks for your reply,
But, am still not able to test it. Could you please give me the clear steps necessary for the same? I have classes in my dll file. Do I have to copy them to my testing application folder?
I am a learner Always
|
|
|
|
|
himangshuS wrote: Do I have to copy them to my testing application folder?
No...
I assume that you have two projects (and you are using VC6 for instance).
Let me say, "dll.dsp" and "exe.dsp". And you have one workspace, say, "all.dsw".
You should insert (using Project menu) dll.dsp and exe.dsp to the all.dsw.
Set the active project as dll project. You will get these from Porject menu.
Set the "executable for debug" for dll project as the exe (output of exe project) in Project > Settings... > Debug(Tab) > "Executable for debug session"
Also set the working folder as the dll's folder (dll\debug or dll\release)
Now you can run the project. It will automatically execute the exe in order to run the dll.
Hope these are clear to you...
If you are making the exe project as active project, set the dependency for exe project as dll project. So that you dont need to build the dll each time you change its code.
- ns ami -
|
|
|
|
|
Thanks,
I got all the settings. Nut Now when I try to create a object of a class(of dll) in my testing application(exe), it says.. undeclared identifier...Why is this?
Thanks in advance
I am a learner Always
|
|
|
|
|
You have a exported class, right?
Are you sure you included the header of that class in the test app?
- ns ami -
|
|
|
|
|
I am really sorry for the basics. Could you please tell me how to export and necessary include statements...also if any other settings has to be changed for dll file
Thanks
I am a learner Always
|
|
|
|
|
himangshuS wrote: I am really sorry for the basics
You should study some basics for dll class exporting.
#ifdef DLL_EXPORT
#define DLL_IMPORTEXPORT __declspec(dllexport)
#else
#define DLL_IMPORTEXPORT __declspec(dllimport)
#endif
class DLL_IMPORTEXPORT CMyClass
{
};
And you have to specify the "DLL_EXPORT" in Project > Settings > "Preprocessor definitions"
And in the test app you can just include the header and use. Also you need to specify the lib file of dll. It is available in the Link(tab), Input(catagory) of the project settings. Give the path to the lib in the "Additional library path"
- ns ami -
|
|
|
|
|
When I try to compile the exe project it through an error
fatal error C1083: Cannot open include file:
When I specify the library file of the dll in the exe project, is it the same path as my ...dll_project/debug folder?
Thanks
I am a learner Always
|
|
|
|
|
himangshuS wrote: fatal error C1083: Cannot open include file:
Check yourself the file path and existance of the file.
himangshuS wrote: When I specify the library file of the dll in the exe project, is it the same path as my ...dll_project/debug folder?
Yes, path where your dll's .lib file exists.
- ns ami -
|
|
|
|
|
still the same error...i checked the file existence...it exist in the dll project folder...not in debug,(but dll' main_application folder)....Do i need to copy paste the header files into the application project workspace..I hope not..
I am using vc++ 6 version.
my trest appplication is mfc, and dll is win32 dll
Regards,
Himangshu
modified on Monday, February 2, 2009 5:24 AM
|
|
|
|
|
You have to set the include path in Test App's Project settings > Preprocessor(catagory) > "Additional include directories"
Eg: "../DllProjectFolder/" or "D:/DllProjectFolder/"
And in the source, you can include the header like
#include <dllmyclas.h>
- ns ami -
|
|
|
|
|
Thanks a lot ns ami
It worked,...But, here is another problem exist..
I had to make my class methods as public.(it was giving the error)..And I made it also...Now when I compiled my dll and then compiled the test application its giving error...
error LNK2001: unresolved external symbol "__declspec(dllimport) public: int __thiscall <<b>class_name>::<<b>method_name>(void)" (__imp_?method_name@class_name@@QAEHXZ)
Debug/testing.exe : fatal error LNK1120: 1 unresolved externals
I am a learner Always
|
|
|
|
|
I think, the lib is not properly included to the test app project.
- ns ami -
|
|
|
|