|
I would make sure the pointer returned from GetParent() is actually the type you think it is. Do something like:
ASSERT_KINDOF(CXFaceRecognitionDlg, m_pParent->GetParent())
|
|
|
|
|
i had ur advice and now roughly can get the root of evil but still have no idea how to solve it. here is the root of evil. (i simplify my previous problem)
----------------------------------------------------------
i try to use a c library which require me to pass a function poinger as callback. hence, i build
a static function inside a class .
however, i face a very strange problem while trying to access a member function through that
static function with the following trick.
i have the following classes:
CXFaceRecognitionDlg - main dialog class and with a CPicture control
CPicture - control derived from CStatic
in CXFaceRecognitionDlg.h
-------------------------
class CXFaceRecognitionDlg : public CDialog
{
public:
int GetDummy(){ return dummy; }
void ShowDummy();
// Dialog Data
//{{AFX_DATA(CXFaceRecognitionDlg)
enum { IDD = IDD_XFACERECOGNITION_DIALOG };
CPicture m_Picture;
protected:
int dummy;
-------------------------
in CXFaceRecognitionDlg.cpp
---------------------------
BOOL CXFaceRecognitionDlg::OnInitDialog()
{
// this is the c library
// this callback will process every seconds
cvcamSetProperty(0, CVCAM_PROP_CALLBACK, CPicture::callback);
// explicitly set to 108
dummy = 108;
}
void CXFaceRecognitionDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CXFaceRecognitionDlg)
DDX_Control(pDX, IDC_PICTURE, m_Picture);
//}}AFX_DATA_MAP
}
void CXFaceRecognitionDlg::ShowDummy()
{
CString s;
s.Format("%i", dummy);
MessageBox(s, s, MB_OK);
}
---------------------------
in CPicture.h
-------------
class CPicture : public CStatic
{
// Construction
public:
static void callback(IplImage* image);
protected:
static CPicture* m_pThis;
-------------
in CPicture.cpp
---------------
CFaceDetectionManager* CPicture::m_spFaceDetectionManager = NULL;
CPicture::CPicture()
{
// I NEED THIS TO ENABLE ME TO ACCESS MEMBER FUNCTION THROUGH STATIC FUNCTION
m_pThis = this;
}
void CPicture::OnLButtonDown(UINT nFlags, CPoint point)
{
// YAHOO! I GET 108 DISPLAY
((CXFaceRecognitionDlg*)GetParent())->ShowDummy();
}
// PLEASE NOTE THAT CALLBACK IS STATIC FUNCTION
void CPicture::callback(IplImage* image)
{
// WILL GET COMPILATION ERROR FOR THE FOLLOWING CODE
// 'CWnd::GetParent' : illegal call of non-static member function
//
// ((CXFaceRecognitionDlg*)GetParent())->ShowDummy();
//
// BUT VALUE 0 IS DISPLAYED
((CXFaceRecognitionDlg*)(m_pThis->GetParent()))->ShowDummy();
}
---------------
I try to debug the application by inserting
ASSERT_KINDOF(CXFaceRecognitionDlg, GetParent()); in CPicture::OnLButtonDown
ASSERT_KINDOF(CXFaceRecognitionDlg, m_pThis->GetParent() ); in CPicture::callback
note that ASSERT_KINDOF(CXFaceRecognitionDlg, m_pThis->GetParent() ); in CPicture::callback will
fail!!!
(1) why m_pThis->GetParent() is not class type of CXFaceRecognitionDlg but can have a access to
function ShowDummy?
(2) how can i avoid that failure at the same time mantaining callback as static and able to
access instance member variable?
thank you.
regards
yccheok
|
|
|
|
|
Hello !!!
I have a CListView with a CListCtrl inside.
Now I want that the horizontal Scroll-Bar is not
dissepearing when it is no more needed.
What can I Do??
with SetScrollInfo() with the Flag SIF_DISABLENOSCROLL
it does not work. But I can all other things set, but not SIF_DISABLENOSCROLL
Why??
Thanx for helping me
schoni
|
|
|
|
|
Hi all,
I have a simple dialog box with two list view controls on it.
the controls both have a vertical scroll bar and are created via Visual Studio (not manually using CreateWindowEx).
I need to syncronize the scrollbars so when a user selects one scrollbar, the other list view's scroll bar also moves (obviously moving the information within as well).
From what I read in MSDN, I thought the scroll messages from a control within were propagated to the parent window (in this case a dialog box).
With this information, I understood it as I could just handle the WM_VSCROLL message in the parent's windproc and figure out where the message came from and do what I got to do (using SetScrollPos and such).
Only thing is, my parent window is not receving ANY messages from the two list view controls.
I don't remember what I need to do so the parent windproc receives these messages so I can handle my scrolling.
Any suggestions on how to get the messages? Other than adding a windproc for each control? I don't really want to do it that way and I'm looking for a better way.
Any suggestions are greatly appreciated.
Thank you!
|
|
|
|
|
i opened a the wave in device and record through the line in. the audio samples are collected in a buffer. i convolve this buffer with a filter and send this buffer back to the wave out device for playback. however it does not play the filtered audio. at the output i get the data from line in. however if the filtered audio is saved to a wave file it gets saved properly and properly played back. can anyone tell me why the filtered data from the buffer is not played then. why can i hear the same as the wave in input. does it have to do something with opening the wave in device.
|
|
|
|
|
Gaurs wrote:
can anyone tell me why the filtered data from the buffer is not played then
This seems like an impossibility. However, if you are trying to do this in "almost" real-time, I think you should to have a look at the IAudioStream (or whatever they were called) interface(s) of DirectX.
|
|
|
|
|
Hi there,
I try to connect to Oracle using C++ and ADO with the following conection string...Upon trying to open, I get an access violation error.
This is the connection string:
"Driver={Microsoft ODBC for Oracle};Server=LST3.WORLD;Uid=MyUserName;Pwd=MyPassword;"
The same set of stuff seem to connect me to the database through VB. Any ideas?
HRESULT hRes;
CLSID clsid;
BOOL bRet = FALSE;
LONG nOption = 1;
CoInitialize(NULL);
hRes = CLSIDFromProgID(L"ADODB.Connection", &clsid);
if (SUCCEEDED(hRes))
{
hRes = CoCreateInstance(
clsid, 0, CLSCTX_INPROC_SERVER, __uuidof(_Connection), (void **)&m_pConnection );
}
else
{
bRet = FALSE;
}
if(SUCCEEDED(hRes))
{
SetDSN(nDatabase);
try
{
hRes = m_pConnection->Open(m_varDSN.bstrVal,L"",L"", adConnectUnspecified);
}
catch (_com_error e)
{
bRet = FALSE;
}
......
|
|
|
|
|
I want to read rtf file format and analyse every char format in rtf file and
draw it by myself! How Can I do it!
ZHANGYIFEI
|
|
|
|
|
|
|
Have a look at the (GPL) source code for AbiWord. Since it imports RTF I think you can find the data you want without too much problems.
|
|
|
|
|
where can i find (GPL) source code for AbiWord ?
ZHANGYIFEI
|
|
|
|
|
Hi guys
Related to my last query is this one.
How would you do to make your code be as fast as possible?
compiler options, tricks in code, etc...
Best Regards
|
|
|
|
|
Intelligence and Experience.
Kuphryn
|
|
|
|
|
|
but that's true, experience is one of the major factor in optimization.
One other thing, is good source level analysis, how can you restructure your source code to remove as much as possible useless computation, for example, loop unfolding, pre-computation of values.
Maximilien Lincourt
For success one must aquire one's self
|
|
|
|
|
Hi Maximilien
I've got an old program that makes 20.000.000.000 calculations in few minutes due to a precalculated tables, etc... I'm relaly happy with speed and clients too. But I was thinking about compiler switches about p4 optimizations.
The program was done before p4 and in my old msdn I haven't found switches about p4 optimization.
I was thinking in MMX optimization for comparisons. Maybe in the future 'cos now it's a lot of work.
Best Regards
|
|
|
|
|
Geesh, you give somebody 20 billion CPM and they want more! What's the world coming to?
|
|
|
|
|
20bilions in some minutes not just in one.
Well The program do the following:
It's about football bets.
I have 15 matches and 3 possible results 1 X 2 (1 local wins X tie 2 visitor wins)
Then you have 3^15 possible combinations = 14.348.907 dif. bets
The program gets these combinations and generate what we call a reduction
that is less bets with a certain garantee.
Ex: how many bets do you need to garantee 14 hits of 15? Because the winner could be anyone.
Then you can generate these bets and you have to check the guarantee that consist to compare 1 by 1 the file 1 (14.348.9079 with the second one (depends if you want just 1 mistake or 2 or 3...)
Then as you can see it's really a lot of comparisons.
Using precalculated tables I could let this in an amount of time really nice, but if could be possible fast calculations it would be nice.
Best regards
Dr.Pi
|
|
|
|
|
Seems to me the problem isn't in the speed of the program, but in the speed (and design) of the algorithm(s). This is often the case with algorithms like this.
At first glance it seems you don't know about combinations and permutations, which I believe could reduce your search set by quite a few order of magnitudes in this case.
You might want to visit at least Google and this place.
|
|
|
|
|
The problem is more complex that it seems. Is not a simple combination problem.
When you have the complete serie of 3^n (n=15) combinations is just a mathematical problem, but when do you have an incomplete set and not regular (not predectable), what combinations do you have to get to have the minimum number of combinations that guarantees n-1 hits? and n-2? and n-3? and all this in the minimum time.
Anyway the program do the reduction of 4.782.969 combinations to 314.569 in 52 secs.
Try to find and save in a file the minimum number of combinations that guarantees n-1 hits from a 3^14 combination file in less time.
The only thing that you have at the beggining is a file like this
1X211X2X12X12X1 .....row 1
X1112X12X12X12X
X212X121X212X12
1111X212XX212XX
.
.
.
.
X22X12X2X12X12X .....row 4.782.969 (and are not sorted)
If you have a better solution, sincerely I'll be really pleased to learn it.
Best Regards
Dr. Pi
|
|
|
|
|
Think of using the INTEL C++-compiler instead of the MSVC++.
I have read a test where the Intel compiler achived a major improve just by recompiling. It can use Hyperthreading, SSE2 and so on. But it is no drop-in replacement, and you need to adapt your program to it.
My opinions may have changed, but not the fact that I am right.
|
|
|
|
|
If possible, you should run your code inside a profiler. The design of your program (and the algorithm choices made for how to process data) will affect how fast the program runs, but you shouldn't unnecessarily make changes to code that is already debugged and running correctly.
What you want to do is identify what areas of the code are using the most cpu time, and concentrate any effort in optimizing to those areas that actually make a difference. Even with a lot of experience with what code sequences are slow versus fast, it is a waste of effort to fix parts that only take a small amount of the total time (even if they are written using a slow algorithm). This is where the profiler will help. Use it to find the areas of your program which are taking the largest amount of time to execute, and concentrate any effort on speedups to those areas. (If one part of the program is taking 90% of the time, any effort spent on improving other parts of the program can only get you at most a 10% improvement).
As far as using tricks - I would avoid any "tricky" sequence of code. You are more likely to get it wrong, and even if you get it right, it makes future maintenance more difficult.
For compiler options, I would just choose whatever optimizations match the most likely target machine for the program.
Best regards,
John
|
|
|
|
|
Thank you a lot.
You're right, the calculation part is the only part that I must optimize 'cos do it in the others is just a waste of time.
What profiler do you use?
Best Regards
Dr.Pi
|
|
|
|
|
Recently, I have been using the Intel VTune performance analyzer. The version that I use supports Visual C++ 6.0. I typically use it to do time-based sampling, where the program collects samples of where the program is executing at a regular time interval.
It works Ok for my usage, but I find that sometimes I need to make calls into the profiler API so that I can isolate just the sections of code that I want to profile. I mostly work on a CAD application where most of the CPU time is spent idling (waiting for user input), so I only turn on the profiling once the user is done with whatever selections they need to make. These calls aren't necessary, but make it easier to figure out the sections that actually need improvements (by removing clock ticks for user idle from the profile data).
If most of the time spent in your program is doing calculations, you probably won't need to do these API calls, as the user input time will still be just a small percentage of the total time. If you don't add these calls, you can profile your program without needing to make any changes. If you add these calls, it only requires minor changes to your program.
Best regards,
John
|
|
|
|