|
I just did this by working from the article at
http://www.microsoft.com/mind/0297/activescripting.asp
Good luck...
|
|
|
|
|
hey guys! i have this socket issue... im trying to connect using this command..
pSockCon->Connect("1.1.1.26", 777)... it works fine as i see the output on my socket workbench... but when i try to connect using this... pSockCon->Connect("1.1.1.26", 2103)... it still connects eventhough i stop already my socket workbench from listening to that port.. actually i cant listen with port number 2103 and it says there "operating system reports:10048 Address in use".. whats with the port 2103? is it always active? my program hangs everytime i use the port 2103 coz "Connect" returns always true eventhough my socket workbench isnt listening... pls help me..
|
|
|
|
|
Will anyone explain to me the advantage of one over the other - Passing the reference and passing the poniter as parameter in function calls
|
|
|
|
|
Hi
My understanding is there is not much difference in using reference and pointers for function calls.
Using reference makes the code neat and does the work of a pointer. It comes handy while using operator overloading etc.
Go through this article
http://www.embedded.com/showArticle.jhtml?articleID=9900082[^]
regards
The Best Relligion is Science.
Once you understand it, you will know God.
|
|
|
|
|
The main advantages of references are that they are strongly type-safe, and cannot be NULL. Sometimes, passing NULL is a valid option, so a reference can't be used. Also, references are not suitable for things like data buffers or arrays, where the type of the data is unknown or variable, or the length of the data is variable. For example, a char* can point to one or more characters, but a char& is a reference to a single character.
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"
|
|
|
|
|
I have a function
Swap(int& a, int& b)
Does your statement "Sometimes, passing NULL is a valid option, so a reference can't be used" means that I cannot call Swap(2, NULL)(for eg.)
It will not give any error. I am using MS VC++ 6.0
|
|
|
|
|
Ranjish wrote:
Does your statement "Sometimes, passing NULL is a valid option, so a reference can't be used" means that I cannot call Swap(2, NULL)(for eg.)
Yes, for two reasons. First, you cannot supply a constant literal (2) as a non-constant reference. Second, you cannot pass NULL as a reference. A reference must always refer to an object.
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"
|
|
|
|
|
Hi Ryan,
I am using MS VC++ 6.0.
The below code will work.
#include <iostream.h>
void Swap(int& a, int& b)
{
a += b;
b = a - b;
a -=b;
}
int main()
{
int x = 2;
int y = NULL;
Swap(x, y);
cout << x << " " << y << endl;
return 0;
}
Is it because of Converting NULL to zero before initialization.
|
|
|
|
|
There's nothing wrong with that code. You're passing x (an int) and y (an int) both as int references, so the code is fine. The contents of the variables don't make any difference, as long as they are variables.
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"
|
|
|
|
|
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
|
|
|
|