|
Rakesh5 wrote: after executing readfile funcion, inifilecontents are showing contents as "some small BOXES" and not the exact content of inf file....
Actually that's the exact file content. Try to show it with, for instance
MessageBoxW(NULL, (LPCWSTR) inifilecontents, L"TEST", MB_OK);
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]
|
|
|
|
|
In short, using the ReadFile, will read the file content as bytes. Neither as unicode nor as MBCS, but simply as binary data. It is our concern whether it should be treated as unicode or not.
I am ignoring the inconsistency of the variables in your sample code. But still I found a mistake in your code.
That is you are allocating the buffer as 'new TCHAR[m_nBufferSize]'. It is wrong since the GetFileSize will return the exact size of the file in number of bytes. So when you are compiling with unicode enabled, the size of the TCHAR will be 2 (means sizeof unsigned short) and the buffer allocated will be twice of what we needed. Also it should be noted that the data read will not be directly converted to unicode (even if the buffer is of TCHAR).
And, from your question I understand that your file will be in unicode format. If this is true, then you can read it as follows. (modifications might be necessary)
int nSize = GetFileSize(...);
byte* pBytes = new byte[nSize];
ReadFile(..., pBytes, ...);
MessageBox(.., LPCTSTR(pBytes), ... );
This is the case when your file is in binary format.
When you save a file as unicode using notepad, you can see the first two bytes will be FF FE. So when you reading the file you can check that for ensuring the file is unicode and can ignore those bytes from using as data.
Suppose the content of a unicode file is 'abcd', then the binary equalent will be FF FE 61 00 62 00 63 00 64 00. You can see this when you open a file as binary in the VC editor itself.
I hope my explanation is clear for you.
(By the way, I am not sure about any APIs which will directly read a unicode file)
- ns ami -
|
|
|
|
|
what is IWshRuntimeLibrary? when can it be used.
|
|
|
|
|
May I politely google that for you [^]?
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]
|
|
|
|
|
I have created an SDI application andi want to add two buttons to it for zoom in and zoom out.how can i do that?
|
|
|
|
|
You want the buttons to be added to the toolbar. Right?
You need to google first, if you have "It's urgent please" mentioned in your question.
_AnShUmAn_
|
|
|
|
|
Open the toolbar in the toolbar editor (double-click on the toolbar in the Resource View) and click on the blank button on the right side of the toolbar to create a new button. Type a suitable ID into the toolbar button's Properties view (something like ID_VIEW_ZOOMIN?). Now draw something on that to represent 'zoom-in' (a magnifying glass with a + usually works). Now repeat (but changing the details as appropriate) for the zoom-out button.
Now you can handle the zoom-in and zoom-out events, probably in your View class.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
|
How to read command line args in vc++.
Is there any predefined function/class available?
|
|
|
|
|
What type of application are you working on?
If it's a simple console based application you can read the information in the main function (usually named as argc and argv).
Also you can see here:Reading Command line arguments[^]
You need to google first, if you have "It's urgent please" mentioned in your question.
_AnShUmAn_
|
|
|
|
|
...and if you're using MFC, see m_lpCmdLine , which is a member of CWinApp .
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Command line arguments are available in the main function of your program (that is WinMain for a GUI application). If you're using MFC , your-CWinApp -derived class provides the m_lpCmdLine [^] member.
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]
|
|
|
|
|
Thanks for the information.
|
|
|
|
|
|
the code below create a folder in drive E:\ called autorun.inf and other line to create inside autorun.inf folder a text file called protection.txt
now what i want is instead of creating these things in drive E:\ i want the user to enter the drive letter that he wants then these files will be created in the entered drive
#include <direct.h>
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
_mkdir("e:/autorun.inf");
ofstream output("e:\\autorun.inf\\protection.txt",ios::out);
output.close();
return 0;
}
Thanks in advance
|
|
|
|
|
whats the problem in achieving it?
accept the drive letter from user,
form a string that has to be passed to _mkdir, and pass it.
first try it, and then post here if you have any problem. we will definitely help you.
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
Hi .
Is this what you want?
#include <direct.h>
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
char root;
char path[64];
cin >> root;
sprintf_s(path, "%c:/autorun.inf", root);
_mkdir(path);
sprintf_s(path, "%s/protection.txt", path);
ofstream output(path,ios::out);
output.close();
return 0;
}
|
|
|
|
|
thank you very much this exactly what i want
but if u do not mind i want to ask u some questions about the code that u wrote
#include <direct.h>
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
char root;
char path[64];
cin >> root;
sprintf_s(path, "%c:/autorun.inf", root);
_mkdir(path);
sprintf_s(path, "%s/protection.txt", path);
ofstream output(path,ios::out);
output.close();
return 0;
}
again thank u very much
|
|
|
|
|
I'm a chinese, my English may be hard to read, I'm sorry for that. But i will try to explain it.
jon ray wrote: char path[64]; //why did u declare path as char and set it to 64
64 isn't a regular number, I got it by counting the length of your longest full path "e:\\autorun.inf\\protection.txt", and just pick a number more than it.
jon ray wrote: sprintf_s(path, "%c:/autorun.inf", root); //what does this thing mean (%c)
%c is mean that it's a character but not others(string), and it's value is determined by 'root'
jon ray wrote: sprintf_s(path, "%s/protection.txt", path); //why did u put two (path) and why did u put here %s instead of %c
%s is mean that it's a string, and it's value is determined by 'path'.
the second 'path' is use to replace the '%s', and then put the result "%s/protection.txt" to the first 'path', now 'path' has become the full path what you want.
|
|
|
|
|
Since you are using C++, try:
string path = root + ":/autorun.inf";
_mkdir(path);
path = path + "/protection.txt";
ofstream output(path, ios::out);
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
how to add command buttons to SDI application?
|
|
|
|
|
where do u want them to be added?
you mean on the View area?
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
|
create the button dynamically.
like
CButton b;
b.Create(...);
try to browse for CButton::Create(...)function.
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|