|
sharanu wrote: I dont have the code
so WTF are you trying to do then ?
|
|
|
|
|
my code is:
int main(int argc, char* argv[])
{
char strfilepath[]={"D:\\s.xml"};
char xmltag[100];
char ch;
ifstream infile(strfilepath);
if(infile)
{
cout<<"current file contents"<<endl;
while(infile.get(ch))
{
if(ch!=EOF)
{
cout.put(ch);
}
}
}
infile.close();
cout<<"Open file to append\n";
ofstream outfile(strfilepath,ios::app);
if(!outfile)
{
cout<<"Unable to open\n";
return 1;
}
cout<<"enter xml contents"<<endl;
cin>>xmltag;
outfile<<xmltag<<endl;
outfile.close();
return 1;
}
Hi,,
I am sharan.Working as a software Engineer in Indo-Fuji Software Company located in BTM Layout.Bangalore.India.
I have Completed my B.E(COmputers)in 2006.ANd I am having 2 years of Exp in VC++.
thanking you
sharan
|
|
|
|
|
damnit.
Edit your message and format this immediately (use <pre></pre> tags around code samples).
BTW, for handling XML stuff, you can always use the TinyXML Library[^].
|
|
|
|
|
my project is a SDI(View base CFormView)
|
|
|
|
|
You could use AfxGetApp() to get the application instance then the m_pMainWnd member of the applications CWinThread base class to get a pointer to the CMainFrame. I'm pretty sure that will work but you're stretching my rusty MFC to the limit there
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
I am trying to resize a control on the event ON_WM_SIZE...
I have created the appropriate handler 'OnSize()' for it in the control class..but the problem is that the OnSize is called once before the control creation...which is ok..but later on when the control container window is resized...OnSize doesn't get called..
Any help is appreciated
Regards,
AbbyIndian
...A Programmer may or may not be the master of the programming language grammar...
|
|
|
|
|
If the window in which you placed the control is resized, the control won't be resized automatically. You'll have to handle that yourself, you'll need to set the new size of the control.
|
|
|
|
|
call MoveWindow in the control's parent OnSize member function to explicitly change the control's size.
|
|
|
|
|
MoveWindow is being called from the parent's OnSize() function....actually it has about 5 controls.....the OnSize() of 4 controls is working but not for the 5th one...maybe I did something wrong in creating the 5th control's ....any idea what the issue could be.. ?
...A Programmer may or may not be the master of the programming language grammar...
|
|
|
|
|
AbbyIndian wrote: maybe I did something wrong in creating the 5th control
or maybe you made a mistake on MoveWindow for that control, but without seeing your code, we can only guess, my friend.
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.
[my articles]
|
|
|
|
|
Typically, in a dialog based application, when you change the size of the dialog, it will not send WM_SIZE message to it's child controls.
I guess you may use some custom controls.
Wish
A Chinese VC++ programmer
|
|
|
|
|
See the Extras section of this article.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi all,
I'm working with some date formating, with local and UTC time format. At the end I've print the result to the console as follows.
cout << stLocal.wMonth << "/" << stLocal.wDay << "/" << stLocal.wYear << " " << stLocal.wHour << ":" << stLocal.wMinute << "\n";
This line of code works fine, but seems this is too dull when passing this time. Actually I want to pass that value as a string(as a single value) and try the following.
ostringstream os;
os << stLocal.wMonth << "/" << stLocal.wDay << "/" << stLocal.wYear << " " << stLocal.wHour << ":" << stLocal.wMinute << "\t";
cout << os;
The thing here the output is just a number, 0012FA3C for all values.
What's wrong with my code.
I appreciate your help all the time...
Eranga
|
|
|
|
|
please reduce the second <pre> by adding line returns in it, because you're breaking the page formatting !
BTW, have you tried to debug the code ? you could check that it's only the cout << os line that is not working properly, but that the os object contanis the correct string in it...
|
|
|
|
|
Oki, I think cout << os; gives the pointer value. So I need to get the string from os, like this.
cout << os.str();
Gives the correct value. Is my conclusion is correct.
I appreciate your help all the time...
Eranga
|
|
|
|
|
[added]
OMG you beat me on time!
[/added]
Eranga Thennakoon wrote: cout << os;//0012FA3C
You're merely asking cout to print the address of the ostringstream object.
You've to do instead:
cout << os.str();
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.
[my articles]
|
|
|
|
|
Yep, that's what I've try pal.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Is it memory safe to use SendMessage(PostMessage) to pass parameters between threads?
There are two threads A and B;
// thread A want to send some message to thread B
code sample about thread A:
{<br />
char sz[] = "Hello, CodeProject";<br />
BOOL b = TRUE;<br />
SendMessage(hWnd, WM_SOMEMESSAGE, (WPARAM)sz, (LPRARM)b);<br />
}<br />
Can I write code like this in thread B to retriecve the message?
{<br />
MSG msg<br />
GetMessage(&msg, hWnd, 0, 0);<br />
char* p = (char*)(msg.wParam)<br />
BOOL b = (BOOL)(msg.lParam)<br />
cout<<p<<endl;
}
Thank you for your reply.
|
|
|
|
|
Neither technique is thread safe: in both cases, sz is local to your function and will be destroyed when the function terminates. It means that in the other thread, dependings of how the threads were processed, you may access memory that has been freed.
That's what is called a 'race condition'. It depends how the two threads were processed and sometimes it will work fine and other times, it will fail.
|
|
|
|
|
Cedric Moonen wrote: sz is local to your function and will be destroyed when the function terminates.
Thank you Cédric Moonen
So , if I want to use SendMessage(PostMessage) to send some more information than WPARAM and LPRAM, I should use new operator to allocate memory on the heap, and after GetMessage returned use delete to free memory?
|
|
|
|
|
Yes, in that case it is safe (even if it is not beautifull ).
|
|
|
|
|
not beautiful?
Is there some beautiful ways to send large objects between threads? How about Memory-mapped files? I think it is not beautiful too. Because after you copy some information in the memory-mapped file, you still need to tell the other thread to retrieve the information.
Thank you!
|
|
|
|
|
When I said not beautifull, it is mainly because in that case your second thread will need a message loop so it is not applicable in all cases. If you have already a message loop in your second thread then it is fine.
There are, I think, better solutions but it all depends of what you want to achieve. What I do in general is having a class ta wraps the threading functionality (have a member function that will be called from the thread) and then if I need to 'exchange' information, I'll do that through class members and I use events to notify the other thread and eventually critical sections to protect the access to the shared resources.
|
|
|
|
|
Cedric Moonen wrote: If you have already a message loop in your second thread then it is fine.
Yes ,one of the thread is a window thread, and the other is a worker thread, after the worker thread finishes it's working, it will Send(Post) a message with a large block of memory to the window thread.
Thank you Cédric Moonen
|
|
|
|
|
Roughly speaking, usually processes need some technique to exchange data, while threads, by nature, already share data. What I mean is that you just don't need to pass messages to you thread but a bit refactoring to your design.
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.
[my articles]
|
|
|
|