|
gSOAP[^]?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I wonder if someone can help me understand why, when I made changes to the following code worked (more like, gave me the result that I wanted) and if I did something wrong which can come back to haunt me later on (don't bash me )
Original Code:
CFileDialog fOpenDlg(true,NULL,NULL,NULL,_T("All Files (*.*)|*.*||"),this);
CString fName = NULL;
string name;
fName = fOpenDlg.GetFileName();
name = fName;
Error: error C2679: binary '=' : no operator found which takes a right-hand operand of type 'CString' (or there is no acceptable conversion)
now the Modified Code (not the final one):
CFileDialog fOpenDlg(true,NULL,NULL,NULL,_T("All Files (*.*)|*.*||"),this);
CString fName = NULL;
string name;
fName = fOpenDlg.GetFileName();
name = *fName;
Observation: if I open a file named test.txt fName gets set to test, and name gets set to t
Final code (giving me the result I wanted, discovered accidentally while applying it elsewhere):
CFileDialog fOpenDlg(true,NULL,NULL,NULL,_T("All Files (*.*)|*.*||"),this);
CString fName = NULL;
string name;
fName = fOpenDlg.GetFileName();
name = (fName+"");
Observation: now if I open a file named test.txt, fName gets set to test, and name ALSO gets set to test. I've been wondering how that +"" changed the behavior
Thanks
|
|
|
|
|
Are you doing a Unicode or an ANSI build?! This works for me, and I am doing a Unicode build.
std::wstring cppStr;
CFileDialog cfd(true);
if(cfd.DoModal()==IDOK)
{
cppStr = cfd.GetFileName();
wcout<<cppStr.c_str();
}
I hope you can figure out your mistakes.
Also, I don't understand why do you need to use std::string if you're already using MFC. Why not use CString ?!
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
oh, i do do a "DoModal()==OK", I thought it didn't concern with the reason the strings behave (which I guess is what I wanted to know). and you are saying I don't need to use std::string with MFC eh? hmm... interesting point, I was basing that part of my code on basic- opening files, loading the data into buffer, copying the data into another file sort of operations. btw, on a new note, how does working with MFC change the need to use different types of variables (in this case, work with CStrings and not with CStrings and std::strings)?
thanks for the patience mate
p.s. oh there's another part of my code which isn't working (based on the examples I read on CFileDialog examples. I wanted to set the default directory to my C: drive when I click the Open button. my code for it is:
fOpenDlg.m_pOFN->lpstrInitialDir = (LPCWSTR)("C:");
which doesn't seem to be working... again im guessing on the way strings behave? (boy my string concepts are weak )
|
|
|
|
|
You can even write inline assembly to manipulate everything. But the question is: Do you really need to do it, given that you're already using a framework which makes things much more simpler?
I am saying that you should not be using std::string in an MFC program. But given that CString does everything that you need to, I simply fail to see any justification for using std::string. (OK, you're manipulating files? Then you could use CFile or CStdioFile or ...).
And why do I use MFC when I can do everything with vanilla C or C++? Because I'd like to leave for home at 5.
I may use something like an std::string within an MFC program very rarely (may be I'm using some third party code and a function expects a reference to an std::string, or whatever)...
sadman89 wrote: drive when I click the Open button. my code for it is:
You are again providing code in bits and pieces. That works for me and I can't tell you why it didn't work in your case unless I can see the whole of your code (relevant code, please).
See if this helps:
CFileDialog cfd(true);
CString szStr;
cfd.m_pOFN->lpstrInitialDir = _T("C:\\");
if(cfd.DoModal == IDOK)
{
szStr = cfd.GetFileName();
AfxMessageBox(szStr);
}
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
ok so i get your point with using CString over std::string in MFCs, however I had to do some operations like name.append(".txt" which don't seem to be working if I declare name as a CString variable. and that m_pOFN->lpstrInitialDir = _T("C:\\"); also doesn't seem to be working. ok so here's ALL (I hope) relavent code related to that function:
::OnBnClickedBrowse()
{
CFileDialog fOpenDlg(true,NULL,NULL,NULL,_T("All Files (*.*)|*.*||"),this);
fOpenDlg.m_pOFN->lpstrTitle= _T("Open File");
fOpenDlg.m_pOFN->lpstrInitialDir = _T("C:\\");
CString fPath = NULL;
CString fName = NULL;
if(fOpenDlg.DoModal() ==IDOK)
{
fPath = fOpenDlg.GetPathName();
fName = fOpenDlg.GetFileName();
}
thats basically all the code concerning lpstrInitialDir.
|
|
|
|
|
sadman89 wrote: however I had to do some operations like name.append(".txt" which don't seem to be working if I declare name as a CString variable.
Append works perfectly. You are most probably doing something wrong. (again, unless I see your code...)
You might as well want to look at the CString::operator+ , just in case you didn't know, you could do this:
<br />
CString szStr(_T("Hello, "));<br />
szStr += _T("world!");
sadman89 wrote: CString fPath = NULL;
CString fName = NULL;
This kind of initialization is not really needed.
Your code works perfectly on my machine. Setting of the initial directory and the title of the open dialog seem to have no problem at all. I don't see what could have gone wrong.
I'm assuming you have *do have* a C drive.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
weird yeah i googled the .append and also the C: drive thingy, works for other ppl. bah, so i won't be able to open the C drive default... noone's gonna die lol. thanks for the help... now on to figure out bigger bugs
|
|
|
|
|
Until you call fOpenDlg.DoModal() , your code is pointless. That aside...
sadman89 wrote: CString fName = NULL;
Why are you assigning NULL to a non-pointer? Not sure how this even compiles.
sadman89 wrote: name = *fName;
This makes no sense.
sadman89 wrote: name = (fName+"");
Nor does this.
"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
|
|
|
|
|
Hi there,
I'm trying to find a string inside a text file, using VC++ 6.0 application.
The logs contained in the text file can grow up to MBs (50 - 70 MB)
My aim here is to search a string in that and need to get the time stamp of last occurrence of the string.
I cant use the sequential search as this process runs as a thread and it runs for every 2 seconds. Sequential search will take too much of time, if the size of the log file grows to MBs.
I thought of using the findstr.exe command to find out the occurrence of the string "Error #1028" by this, all the lines matching the string will be redirected to the file, thus makes easy to find the last occurrence of the matching string.
WinExec("findstr /C:\"ERROR #1028\" C:\\SERVER.log > C:\\temp_log.txt", SW_HIDE)
But, the output seems to be not re-directing to the temp_log.txt file.
I even tried creating the file temp.txt before executing the same, but the contents will be blank. Even I tried the >> operator too.
If i place this same command in a batch file, and invoke the batch file using WinExec(), it works fine.
Please pass on your comments on how this could be achieve or is there any other way to achieve the same, without having a dependency on external DOS command findstr.exe
Thanks in Advance,
Rajesh
|
|
|
|
|
Rajesh_Parameswaran wrote: Sequential search will take too much of time, if the size of the log file grows to MBs.
How do you think findstr works? It does a sequential search through the file...
Even with a naive string search, you can search through 60MB in around 500ms (2.4GHz Core 2Duo, using a file mapping to load the file).
If you apply some algorithm optimisation (we're looking for the last occurrence of a string - start at the end of the file rather than beginning, that's likely to get a lot smaller.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hi Stuart,
Thanks for your response.
Is there a way to do backward read in a file?
I searched in google and i couldn't find useful article on backward reading a file.
Each line in the log file is dynamic. So reading a fixed length of character will end up in middle of a line. The time stamp in the log file is at be beginning of each line and there are changes that it might read half the line, if we try to read as a fixed chunk of data from bottom.
please pass on your comments.
Thanks in Advance,
Rajesh
|
|
|
|
|
I would read the file by mapping it into memory[^], not reading it using file I/O functions. That allows me to treat the file as a continuous block of memory, so searching the file for a string is almost as as simple as using strstr[^] - I actually used this code to search backwards through a file (specified as the first argument on the command line:
int main(int argc, char* argv[])
{
DefaultFileReader fr(argv[1]);
const char* lookBegin = argv[2];
const size_t lookLen = strlen(argv[2]);
const char* lookEnd = argv[2] + lookLen;
const char* p = (const char*)fr.end()-lookLen;
while (p!=(const char*)fr.begin())
{
if (!strncmp(lookBegin, p, lookLen)) break;
--p;
}
size_t firstPos = p - (const char*)fr.begin();
std::cout << firstPos << std::endl;
return 0;
}
DefaultFileReader is a class I've written that memory-maps a file. It has begin() and end() methods to access the memory that has been mapped.
You can see that my code isn't looking for lines in the file - that's not really necessary once you know what text you're looking for (but could be added - line terminators are just characters!).
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Rajesh_Parameswaran wrote: WinExec("findstr /C:\"ERROR #1028\" C:\\SERVER.log > C:\\temp_log.txt", SW_HIDE)
But, the output seems to be not re-directing to the temp_log.txt file.
I even tried creating the file temp.txt before executing the same, but the contents will be blank. Even I tried the >> operator too.
This all has to do with > and >> not being passed on to the command processor. As you've noted, if you want to do it this way, you'll need to write that string to a BAT file and WinExec() that instead.
How is the file formatted? Is it in any order? How often is the file updated?
"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
|
|
|
|
|
Hi David,
This log file is plain text file, a Sybase generated one for replication server and the logging will be very frequent and dynamic.
Sample content of the file listed below:
==================================================================================
I. 2006/03/15 06:50:48. The first transaction for database 'JAGUAR1.blue' has been logged into the exceptions log and skipped.
I. 2006/03/15 06:50:49. A grouped transaction of 2 individual transactions has failed in database 'JAGUAR1.blue'. Each transaction in the group will be executed individually.
E. 2006/03/15 06:50:51. ERROR #1028 DSI EXEC(104(1) JAGUAR1.blue) - dsiqmint.c(3062)
Message from server: Message: 2601, State 1, Severity 14 -- 'Attempt to insert duplicate key row in object 'NIiAppStat' with unique index 'XPKNIiAppStat'
'.
I. 2006/03/15 06:50:51. Message from server: Message: 3621, State 0, Severity 10 -- 'Command has been aborted.
'.
H. 2006/03/15 06:50:51. THREAD FATAL ERROR #5049 DSI EXEC(104(1) JAGUAR1.blue) - dsiqmint.c(3069)
The DSI thread for database 'JAGUAR1.blue' is being shutdown. DSI received data server error #2601 which is mapped to STOP_REPLICATION. See logged data server errors for more information. The data server error was caused by output command #1 mapped from input command #2 of the failed transaction.
I. 2006/03/15 06:50:51. The DSI thread for database 'JAGUAR1.blue' is shutdown.
==============================================================================
I'm looking for time stamp for "ERROR #1028 DSI EXEC(104(1)"
Thanks in Advance,
Rajesh
|
|
|
|
|
I want to Create a logical(not physical)Bad sectors on hard disks!
Is it possible?
If possible what i should know?
----------------------------------------------
I think
A fabricated ECC could be a solution
Originally ECC is made by automatically...
I cannot get a specific answer to insert ECC artificially.
Let`s consider it together...
Thanks Advance.
modified on Thursday, June 25, 2009 1:19 AM
|
|
|
|
|
It is possible for me to say no dont say 'why'?
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
I built kernel with C6. minigui.org see I do not understand.
Who helped write the example minigui and OS kernel dev thanks
by:tuan1111
|
|
|
|
|
tuan1111 wrote: I built kernel with C6. minigui.org see I do not understand.
Who helped write the example minigui and OS kernel dev thanks
Honnestly, I don't think it is very useful to continue posting on this forum unless you improve your english a bit. All your posts were totally undecipherable (at least for me). So, why do you continue posting questions that you alone understand ?
|
|
|
|
|
My Vietnam
I write kernel os.Lam stars using VC6 write kernel and load it.
How to create _asm graphics.h for this kernel and use it in Vc6
by:tuan1111
|
|
|
|
|
Could you please make a more clear request?
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]
|
|
|
|
|
Hello,
I have one problem with two different projects created in VS2003 and VS2005.
First of all I have a MFC extension dll in one project created in VS 2005. When we load this dll through test project created in VS 2005, everything is fine.
Now we need to use this same dll in one of the application created earlier using VS2003. In this application there is one mediator dll which I have compiled in VS 2005 and connected the previous MFC dll to this app.
After this if I do only
LoadLibrary(...) and
FreeLibray(..) immediately;
the VS2005 shows memory leaks in MFC dll before it unloads it.
What should I do?
Can program Money?
|
|
|
|
|
Dynamic linking mixed versions of MFC is an iffy proposition at best.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Very right. I came out of iffy position after I made few changes and compiled the complete application projects in 2003 and then linked them to existing 2003 app. Believe it everything is correct and I have the project ready.
Can program Money?
|
|
|
|
|
Hello
Can anyone tell me like the things to be taken care of, while moving to UNICODE format, because the application am working is going to be supported in multiple languages?
while using functions like strcpy_s, do i need to be more specific about the size_t parameter?
that is, while doing a copy, do i need to specifiy more memory?
Thanks in advance.
|
|
|
|
|