|
Hi all,
How do i control the actions(capturing mouse and keyboard events) and disabling some menu items in IE?
Thanks in advance,
AL
|
|
|
|
|
Hi, I have a logging class which contains a <code>static std::map</code> of logfilename to std::ofstream, so that I can ensure every logging object uses the correct stream.
When I first attempt to access the map in any way, by calling <code>insert()</code> or anything else, I get an Access Violation from within STL. Has anybody come across this before, or am I missing something obvious?
My classes are outlined as follows:
<code>class LogThis
{
public:
LogThis(const std::string& logName);
~LogThis();
...
private:
...
static std::map<std::string, LogFileStream> mLogFileStreams;
};</code>
Where LogFileStream is just a simple class with a pointer to an std::ofstream and a reference counter of how many logging objects are using the stream, so I know when I can close the stream and delete the pointer.
The logging class is contained within a static lib and I am using Visual Studio.Net.
Any help would be much appreciated.
Thanks,
Christopher
The bomb lives only as it is falling
|
|
|
|
|
How have you then "declared" this static variable (mLogFileStreams? By that I mean in the CPP for the class, you will have something to initialise the map, like this:
std::map<std::string, LogFileStream> LogThis::mLogFileStreams;
What have you got there?
Try a simple test, change the map to map "simple" types, ie map int-to-int, that way you can pinpoint the problem a bit more to either the LogFileStream class causing the map problems, or the map itself.
|
|
|
|
|
Yes, I initialise it at the top of my cpp file, otherwise it wouldn't compile.
std::map<std::string, LogFileStream> LogThis::mLogFileStreams = std::map<std::string, LogFileStream>();
I also tried just this:
std::map<std::string, LogFileStream> LogThis::mLogFileStreams;
But it didn't seem to make any difference. Anyway, I shall experiment with some primitive types and report back.
The bomb lives only as it is falling
|
|
|
|
|
<small><b>simcoe23 wrote:</b></small>
<i>Yes, I initialise it at the top of my cpp file, otherwise it wouldn't compile.</i>
Note is says "how have you" not "have you"
Anyway, std::map definatly do work as static memebers, so it's probably something with your other class. For instance this works without problem
typedef map<int, int> MYMAP;
class A
{
public:
static MYMAP aMap;
};
MYMAP A::aMap;
int main(int argc, char* argv[])
{
A aa;
aa.aMap.insert(MYMAP::value_type(3, 3));
return 0;
}
|
|
|
|
|
Hi there, sorry I didn't notice the "how have you" .
I just tried with a std::map<int,int> and exactly the same thing happens.
The map.insert code is being called in the constructor of my main class, might that be a problem? Basically you create this logging object by passing a filename into the constructor, it checks if the file stream is already open, if not it opens a new stream and stores it in this static map using the filename as a key.
The other thing to mention is that the logging object which is being constructed is a global - I declare it using 'extern' at the bottom of my header file, which may or may not be the right thing to do.
The bomb lives only as it is falling
|
|
|
|
|
Yes - Maybe
The important bit is "logging object which is being constructed is a global " does this mean that the class that is using the map, which is static, is also being declared as global? Or does it mean the logging class which uses the map is declared global, then you have another "main" class that uses the logging one, which isn't global?
When your app starts up, the C runtime libray will init all your static and global members and doesn't do these in any perticualr order - when your constructor calls insert on the map, it's likley that the map hasn't been created yet.
Comment out the line that insert's into the map into the ctor, put a break point in your classes ctor, when it gets hit, check the call stack and go back to the _inititem functions - this is the CRT calling the ctors for all your global variables. Step back out of your ctor to this loop, and you should see that the loop then go into the ctor for the map - IE the map is being created after your ctor is being called, and you get a AV.
You could have a Init() method on your logging object or something, there are a few soultions to this problem really.
|
|
|
|
|
Cool, thanks. Changed it so that the stream is only opened the first time you write to it, and that seems to work. Now of course I am having the same problem when the object destructs, but at least i know what's causing it.
Thanks for your time.
The bomb lives only as it is falling
|
|
|
|
|
No problem
Nowt to do today at work anyway
|
|
|
|
|
hello,
i need to adjust the access rights to the local cd drives installed in the computer. for this i'm retrieving kernel object security and adjust the dacl by adding a grant access with the necessary rights for the users group.
this worked perfectly in the past, the settings are applied and the security changes affected the system as expected.
but now the settings are removed after restarting the computer. all functions return a successful condition and the settings are changed as long as the computer is not restarted.
does this have to do with w2k sp3 ? we were using sp1 previously and it was working there.
does anyone has a clue what i can check or where i can search ?
many thanks in advance
enrico
|
|
|
|
|
first: sp4 is the latest!
2nd: why do u need to adjust the access rights for your cd drive?
Don't try it, just do it!
|
|
|
|
|
i need to adjust the security settings to be able to record cds with the nero software even if i do not have admin rights. nero is providing a tool to adjust the burn rights, but i tried to recreate the functionality to include it in another application, so i do not need the nero burn rights tool and can automate the process of changing the security settings.
and this was working perfectly, but in the meantime the behaviour changed. i cannot say, if it is related to the service pack, but i have no idea what i can check. adjusting the security with the nero utility is still working by the way.
|
|
|
|
|
Hello,
I am trying to do a object oriented multithreaded program with MFC.
In order to do that, I have a class CToto whose contructor creates 2 threads with AfxBeginThread. As an argument to AfxBeginThread I pass the this pointer.
CToto::CToto()<br />
{<br />
/...other inits here.../<br />
fastThread = AfxBeginThread((AFX_THREADPROC)ObjectFastThreadRoutine, this);<br />
slowThread = AfxBeginThread((AFX_THREADPROC)ObjectSlowThreadRoutine, this);<br />
}
(The CToto instance is created on the heap with the new operator in the OnInitDialog of a CDialog class.)
The thread proc are as follow:
UINT ObjectFastThreadRoutine(CToto* lpParam) <br />
{ <br />
lpParam->FastThread();<br />
return 0;<br />
}
UINT ObjectSlowThreadRoutine(CToto* lpParam) <br />
{ <br />
lpParam->SlowThread();<br />
return 0;<br />
}
I have therefore two thread running in two members functions of the CToto class. The goal of this approach is to acces to the variables of this class with both threads.
To be thread safe, I read and write in the member variables that I want to share with functions which are protected with CCriticalSection objects, here is one of those functions used to write to the positionMeasured member variable of CToto:
void CToto::SetPosition(double *pos)<br />
{<br />
CSingleLock singleLock(critSectionPosition);
singleLock.Lock();<br />
<br />
for(int i=0; i<4; i++)<br />
{<br />
positionMeasured[i] = pos[i];<br />
}<br />
<br />
singleLock.Unlock();<br />
}
I have three differents member variables such as positionMeasured that are protected like that. All those three variables have Get and Set functions to read and write.
My problem occurs when the SlowThread tries to access to the SetPosition function. I have a debug assertion failed at the CSingleLock singleLock(critSectionPosition); line. The assertion is the following:
CSingleLock::CSingleLock(CSyncObject* pObject, BOOL bInitialLock)<br />
{<br />
ASSERT(pObject != NULL);<br />
----> ASSERT(pObject->IsKindOf(RUNTIME_CLASS(CSyncObject)));<br />
<br />
m_pObject = pObject;<br />
m_hObject = pObject->m_hObject;<br />
m_bAcquired = FALSE;<br />
<br />
if (bInitialLock)<br />
Lock();<br />
}<br />
BOOL CObject::IsKindOf(const CRuntimeClass* pClass) const<br />
{<br />
ASSERT(this != NULL);<br />
------> ASSERT(AfxIsValidAddress(this, sizeof(CObject)));<br />
<br />
CRuntimeClass* pClassThis = GetRuntimeClass();<br />
return pClassThis->IsDerivedFrom(pClass);<br />
}
I really don't know what to do. I am not an expert in multithreading and maybe (sure) I am doing something false with memory access and memory zone of threads. So if anybody can help me on how to solve this problem or can propose me another program structure for one class with shared ressources and two threads accesing them concurently (those threads must be able to access the private members of the class if possible)
Thank a lot for your answers.
Regards
TV
|
|
|
|
|
First of all, you are not _really_ using CSingleLock correctly.
The point of CSingleLock is to basically aid in cleaning up your critical section if your code throws an exception, or returns take this:
fun()
{
CCriticalSection section;
section.lock()
.
.
.
if (ladeda)
return false;
section.unlock();
}
here, if the "if (ladeda)" condition was true and you returned, you would be left with a locked CS. - using it this way you have to remeber to unlcok the CS before you return, it makes it harder to use exceptions or to have multiple return points in a function. CSingleLock overcomes that by locking in the constructor and unlocking in the destuctor, so by declaring one on the stack, your CS will automatically be unlocked when that stack unwinds - where ever you may be.
You use CSingleLock to overcome the problem like this:
fun()
{
CCriticalSection section;
CSingleLock lock(§ion, TRUE).
.
.
if (ladeda)
return false;
// no need to unlock section, done by ~CSingleLock
}
In other words, remove the explicate calls to singleLock.Lock(); and singleLock.Unlock(); in your code, and change the decliaration to be CSingleLock singleLock(critSectionPosition, TRUE); - this causes the constructor to call Lock for you.
As for your actual problem, well, it depends on what type your critSectionPosition data member is... You haven't included that bit ) You have to pass a pointer to a CS (or any other sync object) to CSingleObject, the assert is telling you your what you are passing is not of type CSyncObject - ie your not passing a CCritcalSection* which dervices from CSyncObject.
If you put up the critSectionPosition data type, I should be able to tell you.
|
|
|
|
|
I defined critSectionPosition as a pointer and create the object with new in the CToto constructor. I also tried to create it in the stack and I get the same problem.
I define my CCriticalSection objects as members of CToto because I have a GetPosition and a SetPosition fonction so I need the same CCriticalSection object to lock the position variable which is accessed by those two function independentely.
I juste tried now replacing my CCriticalSection by CMutex and it is working...
I know that CMutex are not well suited for my case so I would really like to manage to do that with CCriticalSection.
Thanks for your time
|
|
|
|
|
Hmm, how very strange
One thing, the nasty casting to AFX_THREADPROC isn't really a good idea, change your function prototypes to be UINT ThreadProc(LPVOID) and then cast the void paramter to the correct type in the thread.
What platform are you using (as in VS.NET/VC6)?
Also, try in your SlowThread just calling critsection->Lock() (ie doing away with the CSingleLock class) what happens then?
|
|
|
|
|
Hi there,
I want to get handle to window of a running instance of an application whose HINSTANCE i have stored in my Win32 application.
How do i do that?
modified 21-Apr-21 21:01pm.
|
|
|
|
|
you can get the handle of this window using
FindWindow(NULL,_T("<caption of this window>")
if you know this caption you can use it directly else
you can get it using the spy++ program of Microsoft Tools
then use the function FindWindow(,);
this is my understanding of your ques.and i hope to satisfy you..
amr abdel mohsen
|
|
|
|
|
HI,
I know how to print a html file using Exec command by which all the prining is done internally . But i want to whether we can do it ourself.Actually i want to change the caption in my language(other than english)in the print dialog box.Since mfc is doing it internally i don't how to change it.So kindly help.Providing some source code would be more helpfull. Thanx in advance
kesh
|
|
|
|
|
One simple way of doing that is to create webbrowser object, load url and print it using IWebBrowser2::ExecWB(OLECMD_PRINT, ...)
I think of couple ways of changing title:
1) Hook PrintDlgA & PrintDlgW (there are must be plenty examples of doing that, www.microsoft.com/msj must have it for sure ) and provide you own template or printhook procedure to hook the wm_initdialog message and change the title.
2) Set windows hook (WH_CALLWNDPROCRET) for the thread and change the title after wm_initdialog was processed.
Edward
|
|
|
|
|
i came across the article at
http://www.codeproject.com/gen/design/singleton.asp#xx372166xx
i try to compile code:
class CMsgHndlr
{
public :
static CMsgHndlr * GetMsgHndlr();
protected :
CMsgHndlr(){}
virtual ~CMsgHndlr(){}
static CMsgHndlr m_MsgHndlr; // Static instance of Message handler // class.
};
CMsgHndlr CMsgHndlr::m_MsgHndlr;
CMsgHndlr * CMsgHndlr::GetMsgHndlr()
{
return & m_MsgHndlr;
}
however, there is a error saying that:
C:\Documents and Settings\ycheok\Desktop\test\test.cpp(11) : error C2248: 'CMsgHndlr::~CMsgHndlr' : cannot access protected member declared in class 'CMsgHndlr'
C:\Documents and Settings\ycheok\Desktop\test\test.cpp(7) : see declaration of 'CMsgHndlr::~CMsgHndlr'
is there any error on the code given by that article?
thank you.
regards
yan cheng
|
|
|
|
|
Hi
I don't use that code for singleton.
You can use locki or boost and also you can read the Modern C++ design written by Andrei Alexandrescu.
Here is my usual singleton code(from the andrei book you can find it at amazon):
#pragma once
template<class Object>
class DefaultCreate{
private:
static Object * _object;
public :
static Object * Create()
{
_object= new Object;
return _object;
}
static void Destroy()
{
delete _object;
}
};
template<class Object>
Object * DefaultCreate<Object>::_object;
template<class SingletonObject,class CreatePolicy=DefaultCreate<SingletonObject> >
class Singleton
{
public:
static SingletonObject & Instance()
{
if(m_singleInstance==NULL)
{
m_singleInstance=CreatePolicy::Create();
atexit(CreatePolicy::Destroy);
}
return *m_singleInstance;
}
private:
~Singleton(void);
Singleton(void);
Singleton(Singleton &);//no copy allowed
Singleton & operator =(const Singleton&);
static SingletonObject * m_singleInstance;
};
template<class SingletonObject,class CreatePolicy>
SingletonObject * MTHSingleton<SingletonObject,CreatePolicy>::m_singleInstance=NULL;
and here is how i declare an object in singleton
class CMsgHndlr
{
void SayHello(){ cout<<"Hello theos"<<endl;
}
typedef Singleton<CMsgHndlr> test;
void gigi()
{
test::Instance().SayHello();
}
Hope this help
/theos
|
|
|
|
|
I have a question regarding Slow StretchBlt when Video Full Hardware Acceleration
is Enabled in WIndows XP.
Here is my computer's spec, (also on a Dell P4 2gHz)
AMD AthlonXP 2000+
512MB DDR266
WD 7200 40GB HD +8MB Cache
GeForce 4MX 440 64MB AGP 4x
Windows XP+SP1a+All current updates
Visual C++ 6 +SP5
I have noticed that when i switch off HW Acceleration that is set to NONE (Display
Prop>Advanced>Troubleshoot>Video HW Acceleration>None) i get faster drawing on
screen with StretchBlt upto 4-6times faster. When i switch HW Acceleration to
FULL, the drawing becomes slower. Here is a sample code that opens a CAPTURE.bmp
file of 360x360 pixel and StretchBlts to screen.
//-------------------------------------------------------
void CSlowBltDlg::OnOK()
{
//timer
CElapsed m_el;
CDC memDCLoad;
CDC *pDC;
CBitmap m_bmpBitmap;
pDC = this->GetDC();
int x_width=360;
int y_height=360;
pDC->SetStretchBltMode(COLORONCOLOR);
LoadBitmap(this,&memDCLoad);
//start timer
m_el.Begin();
pDC->StretchBlt(20,30,200,200,&memDCLoad,0,0,x_width,y_height,SRCCOPY);
//end timer and show on screen
m_el.End();
CString szTime;
szTime.Format("Time = %.3fms", m_el.m_dElapsed*1000);
pDC->TextOut(10, 10, szTime);
}
void LoadBitmap(CSlowBltDlg *myDlg, CDC *memDCLoad)
{
CDC *pDC;
CBitmap m_bmpBitmap;
pDC = myDlg->GetDC();
CString m_sBitmap;
memDCLoad->CreateCompatibleDC(pDC);
static char BASED_CODE szFilter[] = "Bitmap Files (*.bmp)|*.bmp||";
// Create the File Open Dialog
CFileDialog m_ldFile(TRUE, "*.bmp", m_sBitmap,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter);
if (m_ldFile.DoModal() == IDOK)
{
m_sBitmap = m_ldFile.GetPathName();
HBITMAP hBitmap =(HBITMAP)::LoadImage(AfxGetInstanceHandle(),m_sBitmap,IMAGE_BITMAP,0,0,
LR_LOADFROMFILE|LR_DEFAULTCOLOR);
if(hBitmap)
{
if(m_bmpBitmap.DeleteObject())
m_bmpBitmap.Detach();
m_bmpBitmap.Attach(hBitmap);
}
memDCLoad->SelectObject(&m_bmpBitmap);
}
}
//Timing requires CElapsed class available in zip file.. see below
//-------------------------------------------------------
With HW Acc. Full= 6.01ms
With HW Acc. None= 0.8ms
Isnt HW Acc. supposed to make drawing faster? Please comment. I am doing a
realtime image processing program and time is crucial. My current program
StretchBlts with other processing takes 252ms per frame of an image captured from
somewhere (360x360 px) on a Dell Pentium 4 2Ghz with ATI Rage 64MB card(not sure
the card type but it is ATI). Switching of HW Acceleration yields a supprising
result of only 63ms per frame at same dpi. Why is that so? Frame capture is choppy
with HW Acce ON. Is there something i must do to my app to take full advantage of
HW Acc? Thanks
The complete source & exe also available here
http://ucsnet.hypermart.net/SlowBlt.zip
|
|
|
|
|
Hello
Here at work I have inherited an mfc dll project for Visual Studio.net.
When it builds in debug mode both the dll and lib files are created successfully.
But when i build in release mode only the dll is built and not the lib file.
I was wondering if anyone had any suggestions as to how to get visual studio.net to create the missing lib file when i do a release build.
regards
Bryce
---
Publitor, making Pubmed easy.
http://www.sohocode.com/publitor
|
|
|
|
|
|