|
Will anybody expain to me who calls Main() in Windows and where does main returns. Who uses the return value for wht purose. PLease don't just answer it as OS. I am looking for a detailed answer
|
|
|
|
|
Hi,
Open an appln in VC++ give F11(Step Into) it will open up the APPMODUL.CPP file there you can see _tWinMain
Sujan
|
|
|
|
|
Ranjish wrote:
Will anybody expain to me who calls Main() in Windows and where does main returns
When you say main(), I presume that you're talking about a console app.
When you compile a C/C++ application, it's actually not you main() function which will be invoked first. The C/C++ runtime needs to set up some stuff, like initializing global objects, and then it will invoke main().
When main() exits, or when you invoke exit(), it's actually not the last code to run. Again, the C/C++ runtime needs to clean up eg. by running deallocators for global objects.
Ranjish wrote:
Who uses the return value for wht purose.
If you've started a process using spawnl(), you can use _cwait() to get the result code.
"After all it's just text at the end of the day. - Colin Davies
"For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus
|
|
|
|
|
[edit]Missed the ReleaseDC() call... [/edit]
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
But I have called : m_pParent->ReleaseDC(pDC);
Do you think it cann't released the pDC actually?
How can I do?
can I use : ::ReleaseDC(m_pParent->m_hWnd,pDC->GetSafeHdc()); it is testing now.
|
|
|
|
|
If ReleaseDC fails to release a DC it returns 0. If it is returning 1 then it is successfully releasing.
You could check for a 0 return value!
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Walliams (Little Britain)
|
|
|
|
|
Strange! Are you sure you have always called ReleaseDC after each call to GetDC and GetWindowDC elsewhere in your application? (Remember to check all possible code paths)
Other than that I would tend to move the ReleaseDC out of the if statement so that it is always called after GetDC is called, no matter what result you have from GetDC.
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Walliams (Little Britain)
|
|
|
|
|
there is no ..if.. else ..in the original code ,And I called the ReleaseDC().when i found the problem,I add it . I checked the returned value of ReleaseDC(),it's successful everytime.
I have checked all the GetDC in my programm,it realeased OK.
now i do it as follows:
CDC pDC;
if(pDC.Attach(hDC))
{
pDC.BitBlt(rcClient.left, rcClient.top, rcClient.Width(), rcClient.Height(), &m_dcMap, rcClient.left, rcClient.top, SRCCOPY);
}
else
{
TRACE("\ncann't get parent DC\n");
strTemp = "cann't get parent DC";
((CFMapCtrl*)m_pParent)->WriteLogFile(strTemp);
}
pDC.Detach();
hDC is saved at the initial time.
it seems better.
|
|
|
|
|
Good to hear.
Just a small point. You needn't use a new CDC with Attach and Detach if you use the GDI calls direct.
i.e.
::BitBlt(hDC, rcClient.left, rcClient.top, rcClient.Width(), rcClient.Height(), m_dcMap.GetSafeHdc(), rcClient.left, rcClient.top, SRCCOPY);
This makes the code a little simpler.
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Walliams (Little Britain)
|
|
|
|
|
it's an ActiveX to display map .it's main window(m_pParent)refresh every two seconds by calling CMapManager::DrawMap((CRect rcClient).
CMapManager::DrawMap((CRect rcClient)
{
.......................
CDC* pDC = m_pParent->GetDC();
if(pDC != NULL)
{
pDC->BitBlt(rcClient.left, rcClient.top, rcClient.Width(), rcClient.Height(), &m_dcMap, rcClient.left, rcClient.top, SRCCOPY);
m_pParent->ReleaseDC(pDC);
}
else{
TRACE("\ncann't get parent DC\n");
}
}
After running 8-10 hours , pDC will be NULL,and cann't run any longer。Why ?the resource is not release all ?
|
|
|
|
|
My colleague have told me that it may happen sometimes... Unfortunately, we were not quite sure where the problem is... Perhaps the GetDC() only return a temporary DC....Try m_pParent->GetDC()->GetSafeHdc(), save the returned HDC as your class member and use Windows GDI functions instead.
|
|
|
|
|
m_pParent->GetDC(); the returned value is NULL,how can we do GetSafeHdc()?
|
|
|
|
|
Didn't you say that you can get the main window DC before 9~10 hours? I suggest that you can save your HDC as a member of your main window by calling pDC->GetSafeHdc() when you can get pDC that is still not NULL, and pass the member HDC to ::BitBlt(). Maybe that will work? Good luck!
|
|
|
|
|
thanks, I have done as you suggested. it works well longer,But i must test it several days.
|
|
|
|
|
Can someone tell me how to open the other application, for instance, notepad.exe, in a Visual C++ project? Thanks.
|
|
|
|
|
start menu -> Run
enter "notepad.exe" in the edit box (or just "notepad"
hit enter, or click "Ok"
bryce
---
To paraphrase Fred Dagg - the views expressed in this post are bloody good ones.
--
Publitor, making Pubmed easy.
http://www.sohocode.com/publitor
Our kids book :The Snot Goblin
|
|
|
|
|
I'm sorry, but what I mean is how to open the other application( process ) within my program. For instance, when a button in a dialog was pressed, the notepad.exe will be open automatically.
|
|
|
|
|
Use these Api's
Most Simpler One
-->WinExec()
--->ShellExecute
Little Tough
->CreateProcess
-----------------------------
"I Think It Will Help"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
You can use ShellExecute(handle, "open", "File name with path", NULL, NULL, SW_SHOWNORMAL); to open othe application. for eg "path+notepad.exe"
|
|
|
|
|
Does anyone have a suggestion on where I can take a Online programming class? Thanks for anyfeedback.
|
|
|
|
|
I am trying to read a text file that is in the same directory as the program. As I am reading it in, I need to edit some of it and put the text from the text file and the edit into an edit box. I am somewhat new to Visual C++. Can someone Help me out?
Thanks in advance for your help!
Chris
|
|
|
|
|
To get you started; search for CStdioFile in the MSDN library. Of course, you can read a text file using basic file streams as well. But if you implementing an MFC application then using CStdioFile will simplify your efforts. You simply construct an object of this type (CStdioFile is a class type). Read the documentation in the MSDN on how to construct it. There are two very basic functions; ReadString and WriteString. It will read the file line by line and fill a null terminated string. Use a CString or std::string or _TCHAR[SIZE] array, or whatever it is you use to process strings. Read up on CString if you aren't familiar with that. Basically, MFC provides some very simple interfaces for doing what you are doing. Obviously, you'll have to write the C++ code to manipulate the strings as you read them but the CStdioFile should make the file I/O pretty simple. There are many ways to get data into an edit control; I assume you already know how to do that part once you have manipulated the data you've read from the file.
Regards,
Shawn
|
|
|
|
|
As has been pointed out, MFC offers some classes to do this. The other option is the standard ifstream/ofstream classes. I have written articles on these on Code Project, you should check both out before deciding which to use.
If you learn to use streams, they will be useful to you in any C++ setting. However, I'm not familiar enough with the MFC alternatives to know if they have significant other benefits.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
I'm trying to port some code I wrote using DirectSound in C# to Visual C++ (managed). I've got most of it done except for this problem I'm stuck at. I understand that this is a newbie question, so please be gentle
The function I'm having a problem with is CaptureBufferObject->Read(arguments) in C++.
In C#, the function protoype is:
public Array Read(
int bufferStartingLocation,
Type returnedDataType,
LockFlag flag,
int[] ranks
);
My code has the following usage of the Read method.
MemBuffShort = (short[])(StreamCaptureBuffer.Read(StreamCapBuffReadPos, typeof(short), LockFlag.None, 50000));
where MemBuffShort = new short[100000];
In C++, the function prototype is:
public: Array* Read(
int bufferStartingLocation,
Type *returnedDataType,
LockFlag flag,
int ranks __gc[]
);
My problem is with the last parameter: int ranks __gc[]
I tried the following:
static System::Int32 CapBuffPara[] = new System::Int32[] { 50000 };
MemBuff = StreamCapBuffer->Read(StreamCapBuffReadPos, __typeof(int), LockFlag::None, CapBuffPara);
However, I get the following error message:
error C2440: '=' : cannot convert from 'System::Array __gc *' to 'int __gc[]'
How do I solve this problem? What needs to be changed?
Thanks for your help!
|
|
|
|
|
Well, since no one is going to tackle this extremely hard problem, here is the answer.
Instead of the line int rank __gc[], try either int rank[] or int *rank.
Bottom line, the C# line "int[] rank" defines an array of integers. The line "int rank __gc[]" wants to recast __gc[] from the class System::Array to an int array, and it won't work. Either "int rank[]" or "int *rank" define an array of integers.
Geez, people, at least pretend to read the books or understand what the definitions of things are.
|
|
|
|
|