|
Yes I had done a test, even though after deleting its working fine. From where is it referring even after deletion?
|
|
|
|
|
Super Hornet wrote: From where is it referring even after deletion?
Turn your monitor East so that I can see it. But then CPallini, Cedric, David, and all others won't be able to see it.
So, show us your code.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
But the article refered by cedric clearly tells we shouldn't delete.
Here is my code:
BOOL NcEventArrhythmiaOnDlg::OnInitDialog()
{
NcEventSpecificDlg::OnInitDialog();
LOGFONT lf;
GetFont()->GetLogFont(&lf);
lf.lfHeight = -16;
lf.lfWidth = 0;
CFont* pFont = new CFont;
pFont.CreateFontIndirect(&lf);
GetDlgItem(IDC_ARRHYTHMIA_ONSET_TIME)->SetFont(&pFont);
GetDlgItem(IDC_ARRHYTHMIA_ONSET_INFO)->SetFont(&pFont);
GetDlgItem(IDC_CYCLE_LENGHT)->SetFont(&pFont);
GetDlgItem(IDC_ARRHYHMIA_UNIT)->SetFont(&pFont);
pFont->DeleteObject();
if(pFont != NULL)
{
delete pFont;
pFont = NULL;
}
return TRUE;
}
|
|
|
|
|
Super Hornet wrote: GetDlgItem(IDC_ARRHYTHMIA_ONSET_TIME)->SetFont(&pFont);
GetDlgItem(IDC_ARRHYTHMIA_ONSET_INFO)->SetFont(&pFont);
GetDlgItem(IDC_CYCLE_LENGHT)->SetFont(&pFont);
GetDlgItem(IDC_ARRHYHMIA_UNIT)->SetFont(&pFont);
How can the above lines work?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Super Hornet wrote: CFont* pFont = new CFont;
pFont.CreateFontIndirect(&lf);
This code won't compile.
And this too:
Super Hornet wrote: GetDlgItem(IDC_ARRHYTHMIA_ONSET_TIME)->SetFont(&pFont);
GetDlgItem(IDC_ARRHYTHMIA_ONSET_INFO)->SetFont(&pFont);
GetDlgItem(IDC_CYCLE_LENGHT)->SetFont(&pFont);
GetDlgItem(IDC_ARRHYHMIA_UNIT)->SetFont(&pFont);
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
Super Hornet wrote: But the article refered by cedric clearly tells we shouldn't delete.
From the article:
Do not destroy the specified CFont object until after the CWnd control has been destroyed. Windows does not copy the font specified in a SetFont() call. If the font is destroyed before the control is destroyed, unpredictable results can occur.
Well, you wouldn't want the program to work only your computer, but not on the client's. You wouldn't want your program to behave in an unpredictable manner, do you?
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
So finally decided not to delete it in OnintDialog().
|
|
|
|
|
Super Hornet wrote: So finally decided not to delete it in OnintDialog().
Ah - finally I got you convinced to do it the right way.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
Leakfinder shows memory leak in ADORecordset::Getfieldvalue function
the function is called in a loop on a separate thread.
BOOL CADORecordset::GetFieldValue(LPCTSTR lpFieldName, _variant_t& vtValue)
{
try
{
vtValue = m_pRecordset->Fields->GetItem(lpFieldName)->Value; <-leak
return TRUE;
}
catch(_com_error &e)
{
dump_com_error(e);
return FALSE;
}
}
c:\My Projects\PCSRecord_Plus\Code\Shell\LeakFinder.cpp (903): CMallocSpy::PostAlloc
77573015 (ole32): (filename not available): void * __stdcall CSpyMalloc_Alloc(struct IMalloc *,unsigned long)
77114B52 (OLEAUT32): (filename not available): public: void * __thiscall APP_DATA::AllocCachedMem(unsigned long)
77114C7F (OLEAUT32): (filename not available): _SysAllocStringByteLen@8
77114CF0 (OLEAUT32): (filename not available): _ErrStringCopyNoNull@8
7713D325 (OLEAUT32): (filename not available): _VariantCopy@8
c:\program files\microsoft visual studio\vc98\include\comutil.h (1295): _variant_t::operator=
c:\My Projects\PCSRecord_Plus\Code\Client\ADORecordset.cpp (968): CADORecordset::GetFieldValue
what do you think?
|
|
|
|
|
VariantCopy does not frees memory allocated at destination, you need to do that. Problem is , if you are running this function in loop, and using same variable for getting field value for each item in loop, you will definitely leak memory. You need to clear it first. Have a look at VariantCopy[^].
Just to add, VariantCopy is used in assignment operator / copy c'tor of _variant_t .
|
|
|
|
|
thanks for the reply.
I tried that already. Nothing changes.
BOOL CADORecordset::GetFieldValue(LPCTSTR lpFieldName, _variant_t& vtValue)
{
try
{
vtValue.Clear();
vtValue = m_pRecordset->Fields->GetItem(lpFieldName)->Value;
return TRUE;
}
catch(_com_error &e)
{
dump_com_error(e);
return FALSE;
}
}
I also tried clearing the vtValue in the calling function before GetFieldValue, same thing.
|
|
|
|
|
Is the value you are tring to assing is CString ?
It looks like , you are facing similar situation, I faced in past.
Refer, this[^] post.
Though, I never got satisfactory answer.
|
|
|
|
|
Well, I'm using the _variant_t class to have a general solution for getting the values from the recordsetfields, but yes most of the times they are strings, but at that point of the execution I didn't converted them to CString.
I also tried without using _variant_t, using VARIANT and BSTR and _bstr_t. Though the place changes I still have memory leaks somewhere.
I also have issues with CString Allocbuffer.
I'm close to pulling my hair one by one. Have been playing with this for weeks now.
These functions are called on a separate thread, I'm using a jobmanager class I wrote. What I was thinking about lately it might by due to threading issues. Or is it general, but others haven't noticed yet?
I should build a single threaded test program.
|
|
|
|
|
How can I programatically remove a member from the Administrators group?
For your reference :
In Win XP, the Administrator members are accessible through Right click
'My Computer' -> Manage -> Computer Management (Local) -> System Tools ->
Local Users and Groups -> Groups -> Administrators (Double click)
Thanks in Advance
|
|
|
|
|
I wrote the following vb script which removes a specific user from a domain
strDomain="XYZ"
strUser="TestAdminUser"
strGroupName ="Administrators"
Set oDomain = GetObject("WinNT://" & strDomain)
Set oGroup = oDomain.GetObject("Group", strGroupName)
oDomain.Delete "user", strUser
Set oDomain=Nothing
Set oGroup=Nothing
The following code snippet deletes specific user from a group
strDomain="XYZ"
strUser="TestAdminUser"
strGroupName ="Administrators"
Set oDomain = GetObject("WinNT://" & strDomain)
Set oGroup = oDomain.GetObject("Group", strGroupName)
Set ouser = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
oGroup.Remove(ouser.ADsPath)
Set oDomain=Nothing
Set oGroup=Nothing
But, could the above code be replicated in VC++ ?
I've used ShellExecute() to integrate (or run) the vbscript (.vbs) file in VC++ 6.0 code (or programming) ?
Is there a better way ?
|
|
|
|
|
Hi All,
I want to write an application that runs in the background and does not bring up any kind of UI (Not even the command prompt). How can I achieve this?
Thank you,
AJ
|
|
|
|
|
Creating window in Invisible mode can achieve this .
|
|
|
|
|
Hi,
Any idea how I could do this in a command line application?
Thank you,
AJ
|
|
|
|
|
What is the purpose of having an invisible window? What is it going to do? Why should it only be a command line application?
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
try the following,
#ifdef _UNICODE
#pragma comment (linker, "/subsystem:windows /entry:wmainCRTStartup")
#else //_UNICODE
#pragma comment (linker, "/subsystem:windows /entry:mainCRTStartup")
#endif //_UNICODE
it makes your application as windows application and since you are not creating any windows in console application (normally not) no UI is visible.
you can also think about windows NT services.
|
|
|
|
|
I was saying easy way to switch to "Win32 application" from a console application. Sorry if some thing wrong, But i would like to know the technical reason (will be appreciated) that gave me vote 1.
|
|
|
|
|
You can also hide the console window,
ShowWindow(GetConsoleWindow(), SW_HIDE);
|
|
|
|
|
I don't understand why your previous post was voted down. I can only think that someone thinks the OP is trying to do a malicious program, for which you're providing him some assistance and so they voted you down.
Anyways, I know that you won't assist someone to do a malicious program and so I'll try to bring up the score.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
Thank buddy,
Invisible app can be easily created in windows subsystem application, even a beginner (win32) can understand. So nothing prevents he from creating malicious program. He can have good intention also.
|
|
|
|
|
Well, that was only my guess. Besides that, I couldn't think of a reason why someone down-voted you.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|