|
while dynamic_cast is proper C++ option, many windows programmers prefer not to use it for performance reasons (you have to compile with RTTI etc.)
To solve your problem you might use virtual functions
class Figure
{
...
virtual int Radius() const {return 0;}
...
};
class Circle : public Figure
{
...
virtual int Radius() const {return m_radius;}
...
};
class Rectangle: public Figure
{
... //no changes
};
|
|
|
|
|
I think that an object of a derived class can be referenced by a pointer to the parent class, in which case instead of writing
obj[i] = new Circle;
you should write
obj[i] = (Figure *)new Circle;
This makes the obj array hold pointers to Figure, and both Circle and Rectangle can be referenced.
Dave
"You can say that again." -- Dept. of Redundancy Dept.
|
|
|
|
|
The old-fashioned way (not typesafe, but no performance hit) is to typecast the code this as:
int x = ((Circle *)obj[i])->radius;
|
|
|
|
|
a user about my freeware program:
"After performing any calculation, and then after closing DeskCalc SE it locks out the computer from opening up any other program, including DeskCalc SE. If I just open DeskCalc SE, and then close it without performing any calculations it causes no problems. Only when I perform calculations does it prevent me from opening any further programs, including DeskCalc SE. A reboot is the only way to solve this problem."
well this has happend now a few times with win98/2000/XP, and i cant simulate it on
my computers. i spend many hours to find the problem, but i'am giving up now, maybe sombody of you can help me with this strange problem.
|
|
|
|
|
Threads not being terminated ? A Hook which hooks too much ?
~RaGE();
|
|
|
|
|
i use no threads in this program, but i use keyboard hooks, is it possible that key_events can couse this problems. cause one user told me that if he has this problem and is pressing "ESC" afterwards the problem is solved ?
|
|
|
|
|
Hello,
do you know a method how to slow down the network connection of a computer (LAN and internet)? I know that such tools exist but I haven't found any source code on how it's done...
-Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
|
|
|
|
|
I've developed a SDI application using the SwitchToView method
described in:
http://www.codeproject.com/docview/switchingviews.asp?target=switchtoview
I've also follewed articles infos to create View classes to
supply to SwitchToView method.
My problem is the following:
windows messages are only sent to Default View class.
When I switch to another View, this class doesn't receive
any windows messages.
How can I solve this problem ?
Thanks a lot!
|
|
|
|
|
Hi,
I've created two diaglogs with one dialog(child) in transparent modeless mode. (kinda like a picture overlayed onto the background) However, when i try to set the modeless dialog with SetLayeredWindowAttributes it creates another process(like another application running) is there anyway to get ride of this?
|
|
|
|
|
hi,
I want to make a prg to check whenever an application end to writes data to a
file (.txt), so i can open it afterwards.
I tried the (_access) but it didn't worked...
any suggestion?
Many thanks in advance
Aenaos
|
|
|
|
|
You want to know when another application has ended, right? If you created an instance of this other application using CreateProcess(), then you'll want to use WaitForSingleObject().
|
|
|
|
|
It is an external application. It runs on background continusly...
When it receives data from a third application it writes them to a file,
the only thing I can check is whenever this application will stop writting the data to a specific text file. Nothing else.
Have you any suggestion?
Aenaos
|
|
|
|
|
What application? Are you referring to a program that checks the status of a file?
What "application end?"
Kuphryn
|
|
|
|
|
Sounds like the writer program needs to set an Event and the monitoring program can WaitForSingleObject on that Event.
|
|
|
|
|
Hi, I'm writing a function which will create a copy of a tree. The traversal code for source tree is fine, but there is some problem assigning parent node in the destination tree. Please Help!!
extern const CTreeCtrl* m_pSourceTree;
CTreeCtrl m_DestTree;
HTREEITEM m_hDest;
TreeTraverse(m_pSourceTree->GetRootItem());
TREEITEM CKleenCachePage::TreeTraverse(HTREEITEM hStart)
{
HTREEITEM theItem;
if ( hStart == NULL )
return NULL;
if( m_pSourceTree->GetParentItem(hStart) == NULL)
m_hDest= NodeCopy(hStart,NULL);
if ((theItem = m_DestTree.GetChildItem(hStart)) != NULL)
{
m_hDest = NodeCopy(theItem,m_hDest);
theItem = TreeTraverse(theItem);
if (theItem != NULL)
return theItem;
}
if ((theItem = m_DestTree.GetNextSiblingItem(hStart)) != NULL)
{
m_hDest = NodeCopy(theItem,m_hDest);
theItem = TreeTraverse(theItem);
if (theItem != NULL)
return theItem;
}
return theItem;
}
<BR>
HTREEITEM CKleenCachePage::NodeCopy(HTREEITEM hSource, HTREEITEM hDest)
{
int nImage = 0, nSelectedImage = 0;
CString csText = m_pSourceTree->GetItemText(hSource);
m_pSourceTree->GetItemImage(hSource,nImage, nSelectedImage);
return m_DestTree.InsertItem(csText,nImage,nSelectedImage,hDest,TVI_LAST);
}
|
|
|
|
|
I want to build executable with shared MFC dlls to reduce the final size.
But VS7 link my exe file with shared mfc70.dll which is not available on default win98.
So I think I need to link my exe against mfc42.dll which is available on most systems.
What I should gonna do?
|
|
|
|
|
The usual thing to do is distribute the DLL along with your program. It's simple to do if you're packing everything into an intallation executable.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thank you. But in my situation the final size is critical. The aplication is just a some free add-on to some other application. So all should be kept in one executable and size should be no more then 100kB.
|
|
|
|
|
Both mfc42.dll and mfc70.dll are redistributable files there is no garantee that either one already exist on the users machine. Therefore, even if you link with mfc42.dll you still need to include it in the install. If you do not want to include the MFC DLL in your installs then you should not be using MFC.
Trust in the code Luke. Yea right!
|
|
|
|
|
I want to get the Sql Server Name in a local network, how can i to do?
Thanks!
|
|
|
|
|
Variant SQLServer;
Variant ServerList;
int i,nServers;
String sRetValue;
try
{
SQLServer = CreateOleObject("SQLDMO.Application");
}
catch(...)
{
ShowMessage("no SQL Server or SQL Server client!");
return;
}
ServerList= SQLServer.OleFunction("ListAvailableSQLServers");
nServers=ServerList.OlePropertyGet("Count");
ComboBox1->Items->Clear();
for(i=1;i<=nServers;i++)
ComboBox1->Items->Add(ServerList.OleFunction("Item",i));
SQLServer=Unassigned;
ServerList=Unassigned;
///////////////////////////////////
other:
int i;
LPSERVER_INFO_101 pBuf = NULL;
LPSERVER_INFO_101 pTmpBuf;
DWORD dwLevel = 101;
DWORD dwPrefMaxLen = MAX_PREFERRED_LENGTH;
DWORD dwEntriesRead = 0;
DWORD dwTotalEntries = 0;
DWORD dwTotalCount = 0;
DWORD dwServerType = SV_TYPE_SQLSERVER; // SQL server
DWORD dwResumeHandle = 0;
NET_API_STATUS nStatus;
wchar_t *pszServerName = NULL;
try
{
nStatus = NetServerEnum(pszServerName,
dwLevel,
(LPBYTE *) &pBuf,
dwPrefMaxLen,
&dwEntriesRead,
&dwTotalEntries,
dwServerType,
NULL,
&dwResumeHandle);
if ((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA))
{
if ((pTmpBuf = pBuf) != NULL)
{
for (i = 0; i < dwEntriesRead; i++)
{
assert(pTmpBuf != NULL);
if (pTmpBuf == NULL)
{
return;
}
SList->Add((AnsiString)pTmpBuf->sv101_name);
pTmpBuf++;
dwTotalCount++;
}
}
}
if (pBuf != NULL)
NetApiBufferFree(pBuf);
}
catch(...)
{}
|
|
|
|
|
Thank you for your reply, but i have another question: how can i get the Sql Server Name that run on the server?
|
|
|
|
|
Do you mean the name of the Windows NT server that SQL Server is running on? How about GetComputerName[Ex]?
|
|
|
|
|
I mean I want to let my computer search SQL Server's computer name and SQL Server name and list them, but i don't hnow how to do it.
|
|
|
|
|
Try the sp_server_info stored procedure.
|
|
|
|