|
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!)
|
|
|
|
|
Hello,
I need a timer in a user class which calls a member function every 2 seconds. I have tried some timers which have a callback function. But it not possible to call a member function from a callback function.
How can I solve this problem?
Thx for help.
|
|
|
|
|
jsumm wrote: I have tried some timers which have a callback function
Which ones ? Could you post some more info about that ?
Basically if you can supply data (through a parameter) that is passed to your callback function, then you can simply pass the this parameter and convert it back to a class pointer in your callback function. Then you are able to call any public function of your class.
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
Thank you for your help.
I've found a timer tutorial an I'm trying to develop a Multimedia Timer.
Here the source in my user class.
void CALLBACK TimerFunction(UINT wTimerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2)
{
// This is used only to call MMTimerHandler
// Typically, this function is static member of CTimersDlg
CMyClass* obj = (CMyClass*) dwUser;
obj->MMTimerHandler(wTimerID);
}
//----------------------------------------------------------------------------------------
void CMyClass::StartTimer()
{
m_nTimeout = 2000;
TIMECAPS tc;
timeGetDevCaps(&tc, sizeof(TIMECAPS));
DWORD resolution = min(max(tc.wPeriodMin, 0), tc.wPeriodMax);
timeBeginPeriod(resolution);
// create the timer
m_idEvent = timeSetEvent(
m_nTimeout,
resolution,
::TimerFunction,
(DWORD)this,
TIME_PERIODIC);
}
//----------------------------------------------------------------------------------------
void CMyClass::StopTimer()
{
// destroy the timer
timeKillEvent(m_idEvent);
// reset the timer
timeEndPeriod (m_nTimeout);
}
//----------------------------------------------------------------------------------------
void CMyClass::MMTimerHandler(UINT nIDEvent) // called every elTime milliseconds
{
// do what you want to do, but quickly
static int a = 0;
CString str;
str.Format("Timer-Event %d", a++);
m_pTargetDlg->SetState(str);
}
//----------------------------------------------------------------------------------------
It's done in the way you expained, I think. But when the last line of code is done in the MMTimerHandler function (it calls the following Methode in a Dialog class)
void CTestDlg::SetState(CString strState)
{
m_strStatus = strState;
UpdateData(FALSE);
}
it crashes with a Debug Assertion Failed!- Error.
File wincore.cpp
Line 879
Any idea why?
Juergen
|
|
|
|
|
It is better to send a user defined message to your dialog class. And in the event handler of this message, update the data.
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
If I do it in that way
m_pTargetDlg->SetWindowText(str);
it works.
But this is only for testing.
I am trying now to call a member function, which tries a cyclic reconnect to a telnet server after the connection has been closed by the server side.
The connect method works, but if I start it in the timer callback it crashes.
The timer only runs ones. After the first callback I stop the timer and call the connect method, but it crashes.
Hard work, I don't know why...
|
|
|
|
|
Did you read my previous post ? Did you implement it ?
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
I am trying to write an OPC server, opcfoundation.org is no help as one need to be a member of the orgaization. I tried some ActiveX, but with limited flexibility.
Can anyone help?
Sanjay
|
|
|
|