|
George_George wrote: It just mentioned in the reverse order of construction. Not mentioning the order of construction in the link you referred.
Hey, you only asked about resource leak, asked whether the destructors not being called, and asked the order of destruction. Why should I answer you the order of construction?!
George_George wrote: I have found the initialization order below. I think it means construction of member variables before the completion of constructor of current object. I think it also means the construction of member variables are before construction of current object.
So, the reverse order should be, destruct current object, then destruct member variables. Right?
In your case, "yes ", because your example constructs Goo member in the initialization list, which is earlier than Foo constructor.
Maxwell Chen
|
|
|
|
|
Thanks Maxwell,
Question answered.
regards,
George
|
|
|
|
|
Hi,
I have posted a this question earlier regarding a DLL which is a structure orignally developed in a C application which is being exported and which I in my C++ DLL am importing
This structure has structures embedded in it along with typedef (for different data types)
Seems however this structure is being compiled (aligned) differently in the C compile and in the C++
program
I have had answers to this problem from (CodeProject) members to insert #pragma pack to control the alignment
I thought of using extern "C" around the sturcture telling the C++ compiler to compile it as C
my question is regardless of using #pragma pack or extern "C"
would i have to use the #pragma of extern "C" around every different type and structure whitin this structure ???
|
|
|
|
|
Yes, the #pragma pack should be around EVERY structure.
Something like this could be 4, 8, or 16 bytes, depending upon the project settings:
typedef struct _MyTinyStruct {<br />
unsigned short a;<br />
unsigned short b;<br />
} SMyTinyStruct ;
But THIS will always be 4 bytes:
#pragma pack( push, packSMyTinyStruct, 2 )<br />
<br />
typedef struct _MyTinyStruct {<br />
unsigned short a;<br />
unsigned short b;<br />
} SMyTinyStruct ;<br />
<br />
#pragma pack( pop, packSMyTinyStruct )
It is up to you how much pain you want to endure. Using #pragma to me is always less painful.
extern "C" controls naming connnention and has nothign to do with the total size of a data structure.
|
|
|
|
|
Thankx for replying you are right when I didn't code the extern "C" I got link errors as the C compiler (I know its all cl.exe) added _imp to my exported C calls exported for the functions that live in my C++ DLL I thought however it also align evertyhing the C way thankx for letting me know
all thing I have to worry about is the calling convetion though I think both the C and C++ are _cdecl
Sorry I didn't mention you by name in previous E-MAIL hope you are not offended
Thankx
|
|
|
|
|
Hi,
I have a list control box (report view) in my dialog with two columns with fixed width, but I cannot seem to figure out how to prevent the user for resizing them. I've tried to handle the 'HDN_ITEMCHANGING' message for the list control but no luck. Any help would be greatly apperciated.
Using VS 6.0/MFC
Thanks!
|
|
|
|
|
JBAK_CP wrote: I've tried to handle the 'HDN_ITEMCHANGING' message...
But you should be handling HDN_BEGINTRACKA and HDN_BEGINTRACKW in a CHeaderCtrl -derived class instead.
"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..
If you want to fix the width of columns even if user resize them, then use handle NM_CUSTOMDRAW .
in this message handler you again write the code for width of columns
void Cxyz::OnNMCustomdrawListFunc(NMHDR *pNMHDR, LRESULT *pResult)<br />
{<br />
LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);<br />
m_list.SetColumnWidth(1,50);<br />
m_list.SetColumnWidth(2,50);<br />
<br />
*pResult = 0;<br />
}
|
|
|
|
|
Hi there,
I working on an application that uses UDP socket to transfer data, how can I make sure if there is a connection problem? for TCP I get socket connection errors but for UDP, I do not get any error and I need a way to make sure the connection is up or be notified that there is no connection.
Regards,
|
|
|
|
|
It's all up to you to determine whether UDP datagrams get sent and arrive at the other end.
TCP/IP does that for you, which is why it's able to report connection errors.
There's no "connection" with UDP, so it's not possible to have a connection error.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Make an occassional "pulse" check of the clients, send pulse ACKs from the clients. Write some algo to check if the packets did get assemble at the right order. Make a protocol that takes care of these issues and retransmit the lost/unorderd ones, there you go! You've got TCP on hand :P
OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus
Best wishes to Rexx[^]
modified on Wednesday, March 12, 2008 12:43 PM
|
|
|
|
|
Hi there,
it is possible to use connected UDP sockets, however the information you get is limited. Using connect on a UDP socket (it will not cause any network traffic) together with send (instead of the usual sendto ) allows you to get asynchronous error information... e.g. 'connection refused' if the target peer is not listening on given UDP port. It is pretty much limited to that. I am not sure what kind of "connection problems" you wish to detect, but UDP is not very reliable and if you want to make sure that no data is lost or recover from temporary network outages you need to write your own protocol to detect/correct such cases. As a short note, TCP provides this and more for free.
/M
|
|
|
|
|
Thanks for the reply,
The problem is that we have some wireless mobile devices that are talking to a windows application via UDP sockets using SIM card (GPRS), sometimes the mobile device can not send any message to the application and the application does not know if the socket is down or not! I need to get notified in my application about the network issue (socket disconnection...)
thanks,
|
|
|
|
|
Unfortunately, this information is not provided with UDP.
You need to implement a heart beat (or use an existing library that does it for you). Maybe you can implement a simple solution where the Windows application will mark any mobile device "disconnected" which hasn't sent anything within a time intervall. The next time the mobile device sends something it will be marked "connected" again.
Hope it helps!
|
|
|
|
|
I would like to know the behavior of strlen() when an uninitilized char array is passed as a parameter
char my_str[6];
int len = strlen(my_str);
HKEY hKey;
RegOpenKey(HKEY_LOCAL_MACHINE,"HKEY_LOCAL_MACHINE\\SOFTWARE\\Analog Devices\\SMWDMIF\\Settings",&hKey);
RegQueryValueEx(hKey, "Mode", 0, NULL, (LPBYTE)my_str, &len);
what value would len have when the above code gets executed? Will it cause any compiler/runtime errors?
modified on Wednesday, March 12, 2008 11:33 AM
|
|
|
|
|
still, it searches for the '\0' character.
koumodaki wrote: what value would len have when the above code gets executed?
len = number of character preceeding a '\0' character.
koumodaki wrote: RegQueryValueEx(hKey, "Mode", 0, NULL, (LPBYTE)my_str, &len);
here it expects the buffer size not the string len.
|
|
|
|
|
but '\0' is not present. So how does it know the end of the char array? what value gets stored in len?
|
|
|
|
|
i modified my reply please look at it.
|
|
|
|
|
koumodaki wrote: but '\0' is not present.
It is, just not at the location you desire. For example, if my_str resides at memory address 0x1234, then strlen() will start counting from that locaton until it finds a '\0' character. Use your debugger to see this in action.
"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
|
|
|
|
|
my_str is actualy buffer to store the registry key data. Since I am using strlen() to ge the buffer size, I wanted to know the side-effects of using the function this way.
Also I have not initilized my_str to any value. As far as I know only memory is alocatd by the compiler when I define the array. So can I safetly assume that the variable len = 6, the size of decalred array?
|
|
|
|
|
koumodaki wrote: Since I am using strlen() to ge the buffer size...
strlen() dos not get the size of anything. Use sizeof instead.
koumodaki wrote: ...I wanted to know the side-effects of using the function this way.
At a minimum, the program won't work.
koumodaki wrote: Also I have not initilized my_str to any value.
But it does get initialized, whether you did it or not.
koumodaki wrote: So can I safetly assume that the variable len = 6, the size of decalred array?
You can, but you'd be wrong.
"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
|
|
|
|
|
|
koumodaki wrote: Since I am using strlen() to ge the buffer size
buffer size and string len cannot interpretted same.
koumodaki wrote: As far as I know only memory is alocatd by the compiler when I define the array
size of array is the buffer size here.
koumodaki wrote: So can I safetly assume that the variable len = 6, the size of decalred array?
yes, but if your regvalue string length is greater than 5 you won't get the complete string.
|
|
|
|
|
|
koumodaki wrote: I wanted to know the side-effects of using the function this way.
high probability of an Access Violation error, followed by a nasty dialog box and the termination of your application.
|
|
|
|