|
Probably Handle name is used for some convenience, or maybe to hide the original meaning of Handle .
|
|
|
|
|
Yeah, that's correct. However, I'm wondering:
- where need so many levels of indirection?
- wouldn't be better to change anyhow the defined type name to be clearer for anybody what's there?
Ovidiu
|
|
|
|
|
I think we should ask the authors of RTI, where such weird constructions are used, according to Jay03 message.
|
|
|
|
|
It is a very poor way to declare a new type. The reason it is poor is because of the naming. The goal it is trying to accomplish is to declare a new type that is a pointer-to-a-pointer-to-a-pointer-to-a-pointer-to-a-Handle. A better way to write it would be either of the following:
Option 1:
typedef RedirectedHandle ****Handle;
Option 2:
namespace MyStuff
{
typedef Handle **** ::Handle;
}
An even better solution would be to not use that many levels of indirection (who needs 4 levels of indirection for a Handle?) and to use smart pointers.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
A little bit better for everybody... :thumb:
Ovidiu
|
|
|
|
|
void CMyButton::PreSubclassWindow()
{
UINT nBS;
nBS = GetButtonStyle(); // GetStyle & 0xFF == all bs_* OR operator ?
m_nTypeStyle = nBS & BS_TYPEMASK; // GetStyle & 0xFF & 0xF ==? == all bs_* OR operator ?
if (nBS & BS_CHECKBOX)
m_bIsCheckBox = TRUE;
if (m_nTypeStyle == BS_DEFPUSHBUTTON) // why not use m_nTypeStyle & BS_DEFPUSHBUTTON
{
m_bIsDefault = TRUE;
}
ASSERT(m_nTypeStyle != BS_OWNERDRAW);// why not use !(m_nTypeStyle & BS_OWNERDRAW)
ModifyStyle(BS_TYPEMASK, BS_OWNERDRAW, SWP_FRAMECHANGED);
CButton::PreSubclassWindow();
}
LRESULT CMyButton::OnSetStyle(WPARAM wParam, LPARAM lParam)
{
UINT nNewType = (UINT)(wParam & BS_TYPEMASK); // why not use GetButtonStyle() & BS_TYPEMASK -> wParam & 0xFF & 0xF?
if (nNewType == BS_PUSHBUTTON) // why not use nNewType & BS_PUSHBUTTON? (if SetButtonStyle(BS_OWNERDRAW | BS_PUSHBUTTON)
{
m_bIsDefault = FALSE;
}
return DefWindowProc(BM_SETSTYLE,
(wParam & ~BS_TYPEMASK) | BS_OWNERDRAW, lParam); // why in here remove BS_TYPEMASK style?
}
thanks.
|
|
|
|
|
|
Let me guess!
It's the last Code Inspection Report for your project. Right?
Ovidiu Cucu
Microsoft MVP - Visual C++
|
|
|
|
|
this is a class from codeproject, now its class name is CButtonST(version 3.5 is CMyButton).
I only want to know why did author write that otherwise then me?
|
|
|
|
|
hi! My name is JC im from Puerto Rico. Right now my C++ knowledge is a bit "limited"
and Im developing an application tthat will end up updating a txt file in an FTP. I found a class that got the perfecy functions i need made by otom and found here
( http://www.codeproject.com/internet/ftpclientclass.asp ). The functions I need are exactluy the same he puts as an example:
nsFTP::CFTPClient ftpClient;
nsFTP::CLogonInfo logonInfo("localhost", 21, "anonymous",
"anonymous@user.com");
// connect to server
ftpClient.Login(logonInfo);
// do file operations
ftpClient.DownloadFile("/pub/test.txt", "c:\\temp\\test.txt");
ftpClient.UploadFile("c:\\temp\\test.txt", "/upload/test.txt");
// disconnect
ftpClient.Logout();
dat is basically all i need BUT his work is very hard to understand for me and i just dont know WHAT to include and where to include.. Id appreciate any help you guys can give me. Thanks in advance
-JC
|
|
|
|
|
I think he/she still maintains that article page. Why don't you post a message there. I am sure he/she will be happy to assist you.
Best,
Jun
|
|
|
|
|
Hi..
I have a charecter file in my hard drive...i want to read the file charecter by charecter and i wat to write those charecters to a stucture irrespective of their member variables...
birajendu
CyberG India
Delhi
India
|
|
|
|
|
You can still use the fread function and pass the address of your structure. But you have to take care of that because pading bytes are added between the members of your structure (so it is quite dangerous to handle that this way).
BTW, why do you want to do such a thing ?
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
is there any similar procedure as packed structure
birajendu
CyberG India
Delhi
India
|
|
|
|
|
birajendu wrote: is there any similar procedure as packed structure
Uh ? Could you be more explicit ?
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
if we use packed structure in c thne there is no byte padding...can we such technique in VC++
birajendu
CyberG India
Delhi
India
|
|
|
|
|
Yes, you can use pragma pack directive for that. Look at the bottom of this page[^] for an example
But you still didn't answer my question: what is the purpose of doing that this way ?
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
if we use packed structure in c thne there is no byte padding...can we such technique in VC++
birajendu
CyberG India
Delhi
India
|
|
|
|
|
Two approaches often used:
1) open the file and read the entire content into a buffer.
2) create a file-mapping and map the file content to your memory buffer.
Don't load the file content to a sturcture directly. Load it to a buffer (string) first and then do whatever you like with it.
Best,
Jun
|
|
|
|
|
Hi Gurus!
I have an MFC activeX component which creates a memory leak in the application that uses it. The leak is when exiting program. I have created a small example to show you what happens.
In my activeX component I have this method;
Code:
LONG CThursdayActiveXCtrl::getSomething(VARIANT* pVar)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// A safe array of float
CComSafeArray <float> saVars;
// Insert elements into the CComSafeArray
saVars.Add(1); //THIS LINE GIVES A LEAK!!! SEE BELOW
saVars.Add(32);
saVars.Add(43);
// A CComVariant to return to the client
CComVariant varReturn (saVars.Detach ());
varReturn.vt=VT_R4;
return varReturn.Detach (pVar);
}
I have added my activex control to a dialog based MFC application. I have a button, when that button is pushed this method is called:
Code:
void Ctest1Dlg::OnBnClickedButton1()
{
CComVariant varArray;
// Get the array from the server
test.getSomething(&varArray);
// Attach the safe array
CComSafeArray <float> saFromVariant;
saFromVariant.Attach (varArray.parray);
a=saFromVariant.GetAt(0);
b=saFromVariant.GetAt(1);
c=saFromVariant.GetAt(2);
UpdateData(false);
}
My debugging tool, which is DevPartner gives me the following memory leak:
Memory Leak Exiting Program: Address 0x024101A0 (40) allocated by SafeArrayCreate.
The call stack gives me this lines of code causing the leak;
atlsafe.h 534
atlsafe.h 521
atlsafe.h 373
getSomething 195 (which is the line I have marked in the code above).
Can anyone help me out here? This leak is 40 bytes big, and that will become quite a large amount when the method in my real control is invoked approx. 5 times a second!!
Thanks for any help!
-- modified at 14:12 Thursday 29th June, 2006
|
|
|
|
|
pierre_ribery wrote: varReturn.vt=VT_R4;
This is part of your problem. It should be the following:
varReturn.vt = VT_R4 | VT_ARRAY;
Otherwise, when the "smart" classes call ::ClearVariant, it won't be performing the proper cleanup procedure.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Thanks for your reply!
You say part of my problem, is there more that could be corrected?
And, btw, the leaks are still there after I made the change you suggested! I am really lost of how to fix this!
Pierre.
|
|
|
|
|
I said "part of" because I believe you don't need the Detach/Attach methods as well (just not sure on that ... its been a little while since I dealt with Microsoft's COM wrappers).
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
I think one of the problems is this assignment:
varReturn.vt = VT_R4;
I suppose this is unneeded, since varReturn.vt already contains a value, which is VT_ARRAY | VT_R4 .
What happens when you comment this line?
Next, the constructor at
CComVariant varReturn(saVars.Detach());
creates a copy of passed SAFEARRAY object, therefore the source detached object is not deleted and causes memory leaks. I think you should first try this:
CComVariant varReturn((LPSAFEARRAY)saVars);
If it works, you can reconsider your getSomething function and return a SAFEARRAY pointer directly, detached from saVars . In the other function, attach this pointer to a CComSafeArray variable. It will be deleted automatically.
I hope it helps.
-- modified at 10:22 Thursday 29th June, 2006
|
|
|
|
|
Thanks mate!
There is no rating system here right? (well you got it anyway somewhere!)
|
|
|
|