|
capricious_001 wrote: lszLogFile = "C:\\TeSt\TeSt.txt";
This should be:
lszLogFile = "C:\\TeSt\\TeSt.txt";
capricious_001 wrote: Then a handle will not be created.
Why not? Have you checked the return value of GetLastError() ?
capricious_001 wrote: Is there a way to find out what the actual Directory string is?
It's whatever value you have assigned to lszLogFile .
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
lol nono, the path directory is correct. I just forgot the extra backslash in this example.
I tested it. having lszLogFile = "C:\\TeSt\\TeSt.txt"; works rather than having all the characters as lower case. So really the question is how do i retreive the case sensitive file path of that file
-- modified at 13:09 Monday 19th June, 2006
I wrote that piece of code in my original post on the fly. I hate copying and pasting my code because its just too much too read.
|
|
|
|
|
capricious_001 wrote: I hate copying and pasting my code because its just too much too read.
But copy/paste is the preferred method as needless posts can be avoided. You only need to paste the relevant snippets, not an entire program.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
capricious_001 wrote: lszLogFile = "C:\\test\\test.txt";
OK. I've read your modified post.
Now it looks like a "chicken-and-egg" question though.
capricious_001 wrote: Then a handle will not be created. Is there a way to find out what the actual Directory string is?
To retrieve the so-called *exact* file path, you need a valid file handle and pass the valid handle into some API.
To get a file handle without knowing the *exact* case-sensitive path (in your case), you can only input the path in case-insensitive form which results in failure (in your case).
Anyway, my system works very well with both your code snippets. :->
Maxwell Chen
|
|
|
|
|
I used GetLastError() and figured out that it was an issue with my type-casting, but I fixed it lol. Thanks for the help.
|
|
|
|
|
Windows file systems are not case-sensitive. If C:\test\test.txt is failing, it's due to something else, not the case of the letters. Check the value of GetLastError()
--Mike--
Visual C++ MVP
LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
VB > soccer
|
|
|
|
|
hi everybody,
i am bake bihari from bihar .i have one problem that ,i am write different size of string in file but at reading time i don't know size of string which i have to read
,at time i want to read only one string
|
|
|
|
|
you could write and heading integer before each string so that you read it first, and so, can deduce the length of your string...
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
|
|
|
|
|
How are you writing said string to file?
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
One solution can be that every time you insert a new string into file, you insert it in a new line. Now you can get every string using getline(...) function. How's that?
Good luck
We Believe in Excellence
www.aqueelmirza.cjb.net
|
|
|
|
|
One Classical way of doing this is to read the string twice! First time you read it, just read it into a buffer of one char, and count the chars.(I assume you want to read a zero terminated string.) In that case, you know you reached the End of the string when you read a 0. At that stage, you have a Character count, which is the size of the string you want to read. Now you can allocate an ample buffer, and read the lot. Simple enough? Yes but No.
Unfortunately, for reasons long since lost in the mist of history, not all characters always consume one byte. Our friends in Japan and China may have a word or two to say about that, but, atleast in their case it is usefull to their language. In the western case, it is a Hangover from the past. The long and short of it is, that the End of a Line in a Text file is recorded as a \r\n two byte sequence. (This is how it is recorded on your Disk).
When you read it back from your disk into a Buffer, the \r is stripped from the file, and all you will find in your buffer is a single \n.
This has important consequences, the main one being that the offset of a character in the buffer is potentially different to the offset of the same position in the File.
There is a way around all this, the translation mechanism depends on how you open the underlaying file.
If you open a file as fopen("File","r") or fopen("File","w")the Library will insert, or delete the \r bytes when reading or writing between buffer and file.
If you open a file as fopen("File","rb") or fopen("File","wb")the Library read or write between buffer and file without translation.
All tends to work well, if you read a file in the same mode it was written by, and if you do not do daft things, such as trying to count chars in a file. Armed with the above knowledge, I suggest you get creative, and do the needed
LateNightsInNewry
|
|
|
|
|
Hey guys,
I am receiving this error in VC++
testing_project.obj : error LNK2001: unresolved external symbol "bool __cdecl GetRSLocation_Reg(char *)" (?GetRSLocation_Reg@@YA_NPAD@Z)
C:\testing_project.exe : fatal error LNK1120: 1 unresolved externals
</pre
Where <code>char *</code> is a typedef for <code>LPSTR</code>
These are the libraries I have included in my project:
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib comctl32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
Here are my project options
<pre>
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib comctl32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:yes /pdb:"Debug/testing_project.pdb" /debug /machine:I386 /out:"C:\testing_project.exe" /pdbtype:sept
Anyone know what the problem could be?
Thanks in advance!
Robbie
|
|
|
|
|
I fixed it! In my function definition parameters, I was passing a value by reference but in my function prototype I wasnt. Sorry my bad lol.
|
|
|
|
|
Whenever I do:
CString userInput;
CString device,
cmd,
input1,
input2;
int i;
i = _stscanf(userInput,_T("%s %s %s %s"), &device, &cmd, &input1, &input2);
I get this warning:
c:\...cpp(72) : warning C4996: 'swscanf' was declared deprecated
c:\program files\microsoft visual studio 8\vc\include\wchar.h(809) : see declaration of 'swscanf'
Message: 'This function or variable may be unsafe. Consider using swscanf_s instead.
So, I run my application everything prints ok. Then when I goto close my application I get:
"An unhandled win32 exception occurred in LEDs_try2.exe [2860]."
I then click to debug then I get:
Unhandled exception at 0x783252f8 (mfc80ud.dll) in LEDs_try2.exe: 0xC0000005: Access violation writing location 0x0035002e.
-AND-
MS Visual Studio opens up the file: atlsimpstr.h
Points to line 109 which is:
"if( _AtlInterlockedDecrement( &nRefs ) <= 0 )"
Would please someone explain to me what I'm doing wrong?
Thanks.
Kitty5
|
|
|
|
|
I think you should allocate a space for your destination strings, using GetBuffer :
i = _stscanf(userInput,_T("%s %s %s %s"),
device.GetBuffer(256),
cmd.GetBuffer(256),
input.GetBuffer(256),
input2.GetBuffer(256));
device.ReleaseBuffer();
cmd.ReleaseBuffer();
input.ReleaseBuffer();
input2.ReleaseBuffer();
In GetBuffer specify a size wich is enough for your problem.
Hope it help.
|
|
|
|
|
1. initialize your variables !!!!!!
CString userInput<font color=red> = ""</font>;
CString device<font color=red> = ""</font>,
cmd<font color=red> = ""</font>,
input1<font color=red> = ""</font>,
input2<font color=red> = ""</font>;
int i<font color=red> = ""</font>;
2. use the CString::GetBuffer() method to allow a C method to write in your CString...
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
|
|
|
|
|
toxcct wrote: CString userInput = "";
CString device = "",
Doing that with CString objects does nothing but waste time. They initialize to an empty state and do not normally need to be initialized like that. If you do, you end up basically doing a copy operation to copy an empty string.
When you use GetBuffer(...) to write into CString object, remember to use ReleaseBuffer(...) to ensure that the CString correctly handles the changes.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
James R. Twine wrote: Doing that with CString objects does nothing but waste time
waste time ????
hey, this calls the copy constructor, so how can it loose time.
moreover, it's much clean to do so, ,even is the default constructor already creates an empty CString.
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
|
|
|
|
|
toxcct wrote: waste time ????
Yes.
The default constuctor (in VC++ 6.0 at least, the ATL version does stuff a bit different) does something more than just creating an empty CString . There is something called afxEmptyString that is used as the shared reference to an empty string.
Normal construction basically just sets the internal data object pointer to the shared empty string's data object.
toxcct wrote: moreover, it's much clean to do so, ,even is the default constructor already creates an empty CString.
Initializing the object as in your example does not call the copy constructor, and would even be more ineffecient if it did because it would have to create a temporary CString object, initialize it, count the characters in the target string (zero in this case), and if a non-zero count, dynamically allocate memory for the string for it and assign it into the temporary object, and then call the copy constructor using the temporary object. Again, it would "waste time".
Initialzing with a static string causes a overloaded constructor to be used (an optimization to eliminate the need to create a temporary as shown above). This constructor initializes just like the default constructor, counts characters in the target string, and allocates memory and copies the string over if necessary.
All of these things take time. When time is taken for no good reason, it is wasted time. Hence, it wastes time. I hope this clears things up for you.
I understand why some people are ignorant about this - not everyone actually takes a look at what goes on behind the scenes. Having a look at the implementation of CString::CString(LPCTSTR lpsz) and CString::CString() will clear things up.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
Just FYI:
Initialization (or lack thereof) had nothing to do with the original poster's problem.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
FYMNI, my post was a reply to someone other than the OP. My post addressed the incorrect parts of the provided solutions, as well as provided some background that will hopefully get others to learn more and thus become better developers.
You see, some of us are capable of learning something even if provided out of context, and some... as recently demonstrated... simply are not.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
James R. Twine wrote: FYMNI, my post was a reply to someone other than the OP. My post addressed the incorrect parts of the provided solutions, as well as provided some background that will hopefully get others to learn more and thus become better developers.
You see, some of us are capable of learning something even if provided out of context, and some... as recently demonstrated... simply are not.
I wasn't trying to discount what you were saying (nor the discussion) ... just mentioning that the original problem had nothing to do with this line of discussion.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Zac Howland wrote: I wasn't trying to discount what you were saying (nor the discussion) ... just mentioning that the original problem had nothing to do with this line of discussion.
Understood... Tone lowered...
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
You are going to have a couple problems here:
1) When using scanf-derivatives, the %s directive doesn't work quite like you would expect it to. You will probably want to use the %[] directives with the appropriate delimiter, or better yet, write a simple split method that takes a delimiter and splits a CString into a CStringArray. This part of the error will just give you incorrect data.
2) The scanf-methods (as with all C methods) were not designed to work with class objects. You have to give it a pointer to a character buffer. You can either declare a set of char[]'s, or use the GetBuffer/ReleaseBuffer calls appropriately:
CString userInput = _T("");<br />
char device[20] = {0};<br />
char cmd[20] = {0};<br />
char input1[20] = {0};<br />
char input2[20] = {0};<br />
int i = 0;<br />
<br />
i = _stscanf(userInput,_T("%[a-zA-Z0-9] %[a-zA-Z0-9] %[a-zA-Z0-9] %[a-zA-Z0-9]"), device, cmd, input1, input2);
or, alternatively:
CString userInput = _T("");<br />
CString device = _T("");<br />
CString cmd = _T("");<br />
CString input1 = _T("");<br />
CString input2 = _T("");<br />
int i = 0;<br />
<br />
i = _stscanf(userInput,_T("%[a-zA-Z0-9] %[a-zA-Z0-9] %[a-zA-Z0-9] %[a-zA-Z0-9]"), device.GetBuffer(256), cmd.GetBuffer(256), input1.GetBuffer(256), input2.GetBuffer(256));<br />
<br />
device.ReleaseBuffer();<br />
cmd.ReleaseBuffer();<br />
input1.ReleaseBuffer();<br />
input2.ReleaseBuffer();<br />
Passing in the address of a CString object will lead to a stack-corruption and hence your Access Violation.
The old-style C methods (printf, scanf, etc) have been deprecated in VS.Net 2005 (can't remember if they were also in 2003). There is a link in the MSDN documentation that describes their replacements. You can either use those replacements (and avoid the warnings), pragma out the deprecated warnings, or write a split function (which is what it looks like you really want in this case anyway).
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
God I love you guys!
Kitty5
|
|
|
|
|