|
Tom Wright wrote:
This class is a generic class that has no base class to it. It is part of my main app.
Then it is a simple matter of accessing the class' member variable from the main app.
Tom Wright wrote:
So if the class has never been destroyed by my call app...by using the delete function (or goes out of scope)then any data that is in any memory variable in my called class will still reside there...right?
Correct.
Tom Wright wrote:
Can you give an example of when an object is out of scope?
void main( void )
{
int a;
{
int *x;
x = new int;
}
}
Tom Wright wrote:
And is passing data this way a high risk for memory leaks or buffer overruns?
Memory leaks and buffer overruns can happen in any situation. They are not limited to variables going out of scope. Consider:
class someclass
{
public:
void somefunction(int *n)
{
a = n;
}
private:
int *a;
};
void main( void )
{
someclass sc;
{
int x = 5;
sc.somefunction(&x);
}
}
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Why not granting the application a member of type this class?
The destructor will destroy all the statically declared variables. All the dynamically declared variables you have to excplicitely destroy in the destructor.
If the pointer you passed is pointing to some object allocated on the stack, then the pointer will be invalid as soon as the object is out of scope.
If you want the object to be "alive" when it is out of scope, you have to allocate it on the heap (using calloc, malloc (C) or new (C++))
This way the data will reside in memory untill you explicitly call delete on the pointer.
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Okay so in my calling app I could put this:
CGCICsettings* mySettings = new CGCICsettings;<br />
<br />
mySettings->GetRegSettings();<br />
mySettings->ipAddress;<br />
First I call my function call GetRegSettings(); Which is in my new class. It (the function) fills in a variable called ipaddress, which I'll be able to access this data, which is what I'm doing in mySettings->ipAddress. Right? After I'm done with this I delete it.
Does this sound right?
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
What you have looks ok, but without seeing how/where mySettings is used, I suspect allocating the CGCICsettings object on the heap is unnecessary. For example:
void somefunction( void )
{
CGCICsettings* mySettings = new CGCICsettings;
mySettings->GetRegSettings();
delete mySettings;
} In this context, a heap-based object is totally unnecessary.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Hi!
I've got a listbox, and the function (created with the classwizzard) that deals with the ONDBLCLICK message.
How do i get the text of the listbox item that i just dobleclicked?
thanks!!
|
|
|
|
|
Like this:
int nIndex = GetCurSel();
CString strText;
GetText(nIndex, strText);
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
|
I am working on a project. I have to convert some files ( perhaps HTML,MHTML,Doc,Txt etc.) into a single CHM,and also, the User can reload the CHM that had been generated for some modification. I don't even konw how to make and modify a CHM file using MFC. I am using Visual C++ 6.0. I hope some one could give a example. It could just cover only HTML2CHM and reload HTML from CHM for simple.
Thank you very much!
|
|
|
|
|
|
Hi!
i've got a dialog with two bitmaps (CStatic), and i want to do something when i click on each one.
I've got the following code:
<pre>
void CVentanaPizarra::OnLButtonDown(UINT nFlags, CPoint point)
{
CStatic* plapiz = (CStatic*) GetDlgItem(IDC_LAPIZ);
CStatic* pflecha = (CStatic*) GetDlgItem(IDC_FLECHA);
CRect lapizrect, flecharect;
plapiz->GetClientRect(&lapizrect);
pflecha->GetClientRect(&flecharect);
if ((point.x>lapizrect.left) && (point.x<lapizrect.right) && (point.y>lapizrect.top) && (point.y<lapizrect.bottom))
{
AfxMessageBox("lapiz");
}
if ((point.x>flecharect.left) && (point.x<flecharect.right) && (point.y>flecharect.top) && (point.y<flecharect.bottom))
{
AfxMessageBox("Flecha");
}</pre>
this doesn't do what i want. I gets the 'size' of each bitmap, but it doesn't get it's 'size' from the dialog.
example: lapizrect.top is 0, but i want to load it's position from the dialog.
any ideas?? thanks!!
|
|
|
|
|
A client rect always starts from 0,0. You can convert between different coordinate spaces by calling MapWindowPoints
|
|
|
|
|
how could i do it?
thanks!
|
|
|
|
|
kfaday!
You are not lazy, are you
Here is the declaration from MSDN:
void MapWindowPoints( CWnd* pwndTo, LPRECT lpRect ) const;
which I strongly suggest for reading (http://www.msdn.microsoft.com/[^]).
Something like:
CStatic* pflecha = ( CStatic* ) GetDlgItem( IDC_FLECHA );
pflecha->GetClientRect( &flecharect );
pflecha->MapWindowPoints( this, &flecharect );
should get flecharect in the coordinate space for the owning window.
|
|
|
|
|
thanks!!
that did it!!
msdn makes me dizzy sometimes..
there are many MapWindowPoints functions
|
|
|
|
|
Hie, I am a beginner in MFC programming.I want to know how to create a reset button using MFC.
Thanks in advance.
syasya
|
|
|
|
|
You draw a button in the resource editor and label it "Reset"
For more detailed help, you should probably try to describe what you want the button to do.
|
|
|
|
|
I am using Visual C++ 6.0 and am having problems with the threads dialog box. I find that after suspending execution and opening the threads box, sometimes not all the threads in the process are displayed. I can see the threads in a suspended state in Spy++ though.
Has anyone encountered this problem? Any help would be appreciated.
thanks
Man Learns from History that he never learns from History
|
|
|
|
|
I developped a program to communicate on serial port com. It works fine on xp/W2000.
Then I wanted to include this into a bigger project, so I decided to change it into a dll. It works fine on W2000, but the same application using the same dll sometimes doesn't work on WXP.
When I say it doesn't work I mean that the thing that reiceives the data transferred on the serial link acts as if the flow (115200 bauds) was interrupted sometimes.
The priority level of the emission thread is equal to the reception one: THREAD_PRIORITY_HIGHEST. So it should not be interrupted I think. Unless the fact that it is a dll's thread changes the situation?
Does anybody have an idea?
Thanks
|
|
|
|
|
Hello..
Does any one know how to use a managed dll in normal c++. I have written a managed dll with c++.net and i want to use it in my normal c++ project (ide c++.net 2003) Could any one tell me if its possible... or how??
Thank you in advance for taking the time to read this message
|
|
|
|
|
Hi guys
I've reduced the size of a CCombobox and the original font size now is bigger than the edit box part of the combo.
What's the fastest way to change the font size of the combobox?
There is a way without have to derive a new class?
Best Regards
Doc
|
|
|
|
|
Add a CFont member variable (e.g., m_font ) to the dialog's class declaration. In the OnInitDialog() method, add:
m_font.CreateStockObject(ANSI_FIXED_FONT);
m_combobox.SetFont(&m_font);
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
I am able to get the MAC address of any machine connected in my LAN network .
Now How should I extend this app to obtain the MAC address of a remote machine?
Experts Guide
Regards
Black Tiger 007
|
|
|
|
|
blacktiger007 wrote:
How should I extend this app to obtain the MAC address of a remote machine?
What do you mean by "remote?" Any machine besides the one running the code is remote. Yes?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
typedef byte SkNetMAC[6];
bool FkNetGetMacA( CkStr SA, SkNetMAC &MAC )
{
if( SA.IsEmpty() ) return(false);
#if 1 // get local or remote MAC given an IP using ARP (Win2K+)
ulong rc = 0,
ml = sizeof(MAC);
IPAddr ip = inet_addr( SA.PtrSafe(0) );
rc = ::SendARP(ip, 0, (ulong*)&MAC, &ml);
#else // get local MAC associated with IP by querying adapter info (Win*)
ulong rc = 0,
al = 0;
IP_ADAPTER_INFO *ai = NULL,
*ac = NULL;
IP_ADDR_STRING *ip = NULL;
rc = ::GetAdaptersInfo(ai, &al);
if( rc != ERROR_BUFFER_OVERFLOW ) return(false);
ai = (IP_ADAPTER_INFO*)ckMemTemp.Calloc(al);
if( !ai ) return(false);
rc = ::GetAdaptersInfo(ai, &al);
if( rc != ERROR_SUCCESS ) goto e_FkNetGetMacA;
for( ac = ai; ac; ac = ac->Next ) {
for( ip = &ac->IpAddressList; ip; ip = ip->Next ) {
if( SA == ip->IpAddress.String ) {
FkMemCpy(ac->Address, &MAC, sizeof(MAC));
goto e_FkNetGetMacA;
}
}
}
e_FkNetGetMacA:
ckMemTemp.Free(ai);
#endif
return(true);
}
...cmk
Save the whales - collect the whole set
|
|
|
|
|
Am looking for PHP code to get the Mac address of a machine and I think you got the answer.
|
|
|
|