|
Can you post relevant code?
Regards,
Sandip.
|
|
|
|
|
here it goes.this is my critical section class. Whenever I want critical section I will just create object of this class and call request() and release() functions to lock and unlock.It is giving me run time exception in the destructor of this class. When executing this destructor(DeleteCritical section) it is saying critical sectio not initialised.
class DSCriticalSection
{
public:
DSCriticalSection()
: m_nLockCount(0)
{
InitializeCriticalSection(&_section );
}
~DSCriticalSection()
{
DeleteCriticalSection( &_section );
}
inline void Request() const
{
EnterCriticalSection( &_section );
::InterlockedIncrement(&m_nLockCount);
}
inline void Release() const
{
if (::InterlockedExchange(&m_nLockCount, m_nLockCount) > 0)
{
::InterlockedDecrement(&m_nLockCount);
LeaveCriticalSection( &_section );
}
}
inline long GetLockCount() const
{
return m_nLockCount;
}
private:
mutable CRITICAL_SECTION _section;
mutable long m_nLockCount;
};
|
|
|
|
|
Did you verify that your destructor is getting called only once??
MSDN Says
After a critical section object has been deleted, do not reference the object in any function that operates on critical sections (such as EnterCriticalSection, TryEnterCriticalSection, and LeaveCriticalSection) other than InitializeCriticalSection and InitializeCriticalSectionAndSpinCount. If you attempt to do so, memory corruption and other unexpected errors can occur.
Regards,
Sandip.
|
|
|
|
|
Hello,
I have a toolbar with several icons in it and there is one icon that I must change at runtime. How can I manage this?
I have tried someting like this, but the code crashes...
CToolBarCtrl& tb = m_wndToolBar.GetToolBarCtrl();
int iButtonCount = tb.GetButtonCount();
CDC dcMemToolbar;
CDC dcMemSrc;
CBitmap SrcBmp;
CBitmap NewBmp;
CBitmap* pOldSrcBmp = NULL;
CDC* pDc = GetDC();
dcMemToolbar.CreateCompatibleDC(pDc);
dcMemSrc.CreateCompatibleDC(pDc);
SrcBmp.LoadBitmap(IDB_TOOLBAR);
pOldSrcBmp = dcMemSrc.SelectObject(&SrcBmp);
dcMemToolbar.BitBlt(0, 0, iButtonCount*16, 16, &dcMemSrc, 0, 0, SRCCOPY);
NewBmp.LoadBitmap(IDB_INVALID_ICON);
dcMemSrc.SelectObject(&NewBmp);
dcMemToolbar.BitBlt(0, 0, 16, 16, &dcMemSrc, 0, 0, SRCCOPY);
dcMemSrc.SelectObject(pOldSrcBmp);
m_wndToolBar.SetBitmap(SrcBmp);
Thank you
|
|
|
|
|
Better to handle using CImageList it will be easy and convenient. Please try in this way.
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
Hello everyone,
What is the scene behind the option of merge proxy/stub code in ATL project? My confusion is, COM (in-process server) is a DLL, proxy is another DLL normally, how could two DLLs be merged into one DLL?
thanks in advance,
George
|
|
|
|
|
George_George wrote: My confusion is, COM (in-process server) is a DLL, proxy is another DLL normally, how could two DLLs be merged into one DLL?
For the most part, you can put whatever you want in a DLL. Perhaps you could be more specific about your confusion?
led mike
|
|
|
|
|
Thanks led mike,
I have made more study by myself. Do you think my following understading are both correct?
- If separate coclass code and proxy code into two DLLs, under Windows registry, we need to register coclass DLL under coclass CLSID and register proxy DLL proxy coclass CLSID;
- If bundle coclass code with proxy code, under Windows registry, we register both the DLL (bundled) under both original coclass CLSID and proxy coclass CLSID.
Both are correct?
regards,
George
|
|
|
|
|
George_George wrote: - If separate coclass code and proxy code into two DLLs, under Windows registry, we need to register coclass DLL under coclass CLSID and register proxy DLL proxy coclass CLSID;
- If bundle coclass code with proxy code, under Windows registry, we register both the DLL (bundled) under both original coclass CLSID and proxy coclass CLSID.
Both are correct?
I don't know because I don't really understand what you said, but basically because you start each statement with "if" I would say, NO not correct.
You seem to be over complicating the issue, something it seems you frequently do. There is no "if". There must be a registry entry pointing to the DLL that the component is in, period. No "if" for pointing to the DLL, it must be done, always, period.
Your question seems to be focused on the COM Proxy. To find the Proxy the registry mapping entry[^] is used. Since this mapping is a pointer to another CLSID then that CLSID must have an entry that points the DLL just as we stated above.
Also Make sure you understand COM Apartments and Marshalling[^] to be able to understand the Proxy Registry entries.
led mike
|
|
|
|
|
Thanks led mike,
I have made some study. Sorry that I think my bad description before makes your confused. English is not my native language.
Could you help to review whether my following understandings are correct?
1. when using merge option in ATL, only one DLL file will be generated, and it will be registered under both original coclass CLSID and the IID mapped proxy CLSID;
2. when not using merge option in ATL, two DLLs will be generated, one for original coclass object and the other for the proxy object, and they are registered separately under original coclass CLSID/ and the IID mapped proxy CLSID.
regards,
George
|
|
|
|
|
Hi Friends,
I need to get all the files from a directory in an array. But i cant use CFileDialog..
The path is constant like "C:\\JPEG". From this folder i need to get all the files.
Could any one help me find out.
Thanks in advance...
Thanks and Regards.
SANTHOSH V
|
|
|
|
|
FindFirstFile/FindNextFile
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
See the sample from MSDN. Hope you can use MFC
void Recurse(LPCTSTR pstr)
{
CFileFind finder;
CString strWildcard(pstr);
strWildcard += _T("\\*.*");
BOOL bWorking = finder.FindFile(strWildcard);
while (bWorking)
{
bWorking = finder.FindNextFile();
if (finder.IsDots())
continue;
if (finder.IsDirectory())
{
CString str = finder.GetFilePath();
TRACE(_T("%s\n"), (LPCTSTR)str);
Recurse(str);
}
}
finder.Close();
}
void PrintDirs()
{
Recurse(_T("C:\\JPG"));
}
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
|
Use the CFileFind class.
1) Use CFileFind::FindFile() and CFileFind::FindNextFile() to iterate through the directories and files.
2) Use CFileFind::IsDirectory() function to determine whether its file/folder and just add it to your array.
3) You can get the file name by using CFileFind::GetFileName() and file path by calling CFileFind::GetFilePath() .
if you need the windows api itself, have a look at FindFirstFile() and FindNextFile() .
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Little late..
Some body didn't like it
Regards,
Sandip.
modified on Wednesday, August 6, 2008 6:59 AM
|
|
|
|
|
My keyboard is a bit slow.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Don't worry pal!
I've voted a 5.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
santhoshv84 wrote: I need to get all the files from a directory in an array. But i cant use CFileDialog..
Even if you could, why would you want/need to?
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Hi Friends,
I have written the following code for knowing whether i have access to a particular directory.
CreateFile( (LPCTSTR)szDir, 0, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
where szDir is "C:\\ProgramData\\NewFolder" . It has all kind of access permission.
This is working fine in all OS,but not in Vista.
Can someone tell me the reason.
I am getting ACCESS_DENIED on Vista.
Please try the same on your machine and you will also see same behavior.
Thanks in advance.
Appu..
"Never explain yourself to anyone.
Because the person who likes you does n't need it.
And the person who dislikes you won't believe it."
|
|
|
|
|
NiceNaidu am getting ACCESS_DENIED on Vista.
I read lot of similar problem with vista in past few days on this forum and always solution was you require Administrator access.
Regards,
Sandip.
|
|
|
|
|
To execute your code in Vista you would need to run your application under the admin account. Does your code work when you are logged in as an admin
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
I am running as Administrator.
Appu..
"Never explain yourself to anyone.
Because the person who likes you does n't need it.
And the person who dislikes you won't believe it."
|
|
|
|
|
Are you trying to create directory using CreateFile ??
An application cannot create a directory by using CreateFile, therefore only the OPEN_EXISTING value is valid for dwCreationDisposition for this use case.
Regards,
Sandip.
modified on Wednesday, August 6, 2008 6:43 AM
|
|
|
|
|
No. I am trying to check whether i have access permissions to an existing directory.
Appu..
"Never explain yourself to anyone.
Because the person who likes you does n't need it.
And the person who dislikes you won't believe it."
|
|
|
|