|
CNewbie wrote:
Finally got it working
So what was the final solution?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Your functions are public members. Are you initializing them in the .cpp file at the global scope or in a member function? If global, then I think that you are defining a new array that happens to have the same name as your member variable. You are not assigning values to your member array. Then when you call the function, the array is not initialized. Try this:
In your OnInitDialog():
// Init the functions pointers here
functionarray1[0] = CDialog::Func1 ;
functionarray1[1] = CDialog::Func2 ;
Later:
// call the functions
functionarray1[0]() ;
functionarray1[1]() ;
Make sure you declare Func1 and Func2 as static in CDialog.h
void (*functionarray1[48])();
void static Func1() ;
void static Func2() ;
Coadtoad
|
|
|
|
|
yes coadtoad, that is exactly what I am doing. I am initializing them at the global level in the .cpp file as such:
void (TMyClass::*funcArr2[48])() = {CDialog::func1,CDialog::func2};
I did it this way because I already know what functions I want in there, this is the way I did it in C and because it is less code to wirte then If i do it within a member function like initdialog.
Also is it a rule that the member functions have to be static?
|
|
|
|
|
If you want to have function pointers, I believe that the functions must be static, then you can't see the member variables from the static function. You may need to use a different approach like calling a CDialog member function that uses a switch statement to call the member functions. A little bit more messy, but you will have better encapsulation than writing a series of static functions.
Coadtoad
|
|
|
|
|
BOOL CMainFrame::OnCommand(WPARAM wParam, LPARAM lParam)
{
CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd();
CMyView* pView= (CMyView*)pFrame->GetActiveView();
pView->m_MyVar = 8;//<== Error occur here
//...........
}
How can I access variables in CMyView ?
Thanks in advance
|
|
|
|
|
What is the error you are getting? We are not mind readers (at least I'm not) and we can not see your screen, so you are going to have to give more infomation.
|
|
|
|
|
It appearces an error : Unhandled exception in ClipboardViewer.exe: 0xC0000005: Access Violation
|
|
|
|
|
The first *major* error that you're making is that you're not even verifying that the view pointer is valid. Since you're getting an access violation, it would appear that the view pointer is not valid. I would guess that you're calling GetActiveView in a state before the view is created.
|
|
|
|
|
I run my MDI project, in the first time, my program has one view, but when I click menu, the error occurres
Could you tell me how I can access variables in CMyView from CMainFrame
Thanks in advance
|
|
|
|
|
I found ways to get CMyView
(*)Get CMyView for SDI
+Method 1:
CMyView* pView = (CMyView*)AfxGetMainWnd();
+Method 2:
CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd();
CMyView* pView = (CMyView*)pFrame->GetActiveView();
(*)Get CMyView for MDI
CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
CMDIChildWnd* pChild = (CMDIChildWnd*)pFrame->GetActiveFrame();
CMyView* pView = (CMyView*)pChild->GetActiveView();
;P
|
|
|
|
|
Hi, does anyone know how to use RLC? Can xplain how it is use? Can it be use to compress a DICOM image into a smaller file size? The purpose of reducing the size is to save space. Can it be done? Please help. Thank you.
|
|
|
|
|
Hi everyone,
I can't find any solution for my problem. I have application based on MFC App. The Doc/View architecture is off. After creating main frame I create main view window. Main view window creates two child windows (top part modeless dialog, and bottom part MSFlexGrid). The main part is top dialog since there will many others dialogs created and deleted dynamicaly. Grid is read only.
There is a basic toolbar and Edit menu.
The question is that how to enable (write?) message handling to pass cut, copy and paste to dialog. So picking (if enabled; now update command does not work so it is disabled) a copy from menu will copy text from dialof edit control and paste will paste data into control (which has focus).
I think this can be done by enabling correct message passing.. So it will be similar to doc/view mechanism. I tried with OnCmdMsg but I stuck on stack overflow.
I'm asking for help since I can't figure out any particular category to search in.
Thanks for any help.
regards,
slawek
Slawek
|
|
|
|
|
I have been looking for a simple free grid control to use in the view for a SDI-MFC-app. I want to show about 7 columns, of which one has editable cells. No databases.
In VS6, the best I could find was the MSFlexGrid ActiveX control.
In VS .Net I didn't find that control, but I found another grid control in the .NET-forms. I don't know how to use .NET-forms, so I don't want to use that one.
Any suggestions?
|
|
|
|
|
I have a function that recursively counts the number of files of a given type from the specified path.
It works as desired when used as a regualar function but I am trying to use this function in a worker thread that would return the number of files counted.
I have tried everything that I can think of but the results is always zero.
Here is the struct that I pass as a param to the threadproc
struct THREADSTRUCT
{
CString filename;
int count;
} ;
Here is my calling function.
int CPlayer::CountFiles( string path )
{
_paramCount->filename = path.c_str();
_paramCount->count = 0;
AfxBeginThread( Count, _paramCount );
return _paramCount->count;
}
Here is my threadproc
UINT Count( LPVOID pParam )
{
THREADSTRUCT* ts = (THREADSTRUCT*)pParam;
assert( !ts->filename.IsEmpty() );
int count = 0;
vector< string > files;
vector< string > dirs;
string path = ts->filename.GetBuffer();
string types[] =
{
".mp3",".mp2",".mp1",".ogg",".flac",".flc",".mpc",".ape",".ofr",".mpa",".wma"
};
int size = dim(types);
if( *(path.end() - 1) != '\\' && *(path.end() - 1) != '/' )
path += '\\';
string spec( path + "*.*" );
_finddata_t fd;
int handle = (int)_findfirst( spec.c_str(), &fd );
if( handle == -1 )
return 0;
do
{
if( fd.attrib & _A_SUBDIR )
{
if( fd.name != string(".") && fd.name != string("..") )
dirs.push_back( path + fd.name );
}
else
{
if( find_if( types, types+size, is_ext( fd.name ) ) != types+size )
{
files.push_back( path + fd.name );
count++;
ts->count++;
ct++;
pCPlayer->_paramCount->count++;
}
}
}while( !_findnext( handle, &fd ) );
_findclose(handle );
for( size_t i=0; i<dirs.size(); ++i )
{
pCPlayer->_paramCount->filename = dirs[i].c_str();
count += (int)Count( pCPlayer->_paramCount );
}
return count;
}
I have tried global variables and nothing seems to work. What am I missing?
|
|
|
|
|
Your problem is that the main thread ends its work before the working thread gets a chance to do anything. it even does not has time for the context switch. You should use events. Check the WaitForSingleObject(), CreateEvent() and SetEvent() functions in MSDN. Generally you should wait for the event in the main thread and send it from the working thread when it's finished.
Good luck
DavidR
|
|
|
|
|
What do you mean my main thread is ending before the worker thread does anything?
I am starting the worker thread in OninitDialog() so the main thread is not ending.
Thanks for the direction, I will give those functions a whirl.
|
|
|
|
|
The start of the thread is asynchronous. IOW, you specify to start the thread and pass a fcn pointer and the call returns immediately. In the background the thread is started. Therefore, you have to decide how you want your thread to communicate back to the caller. David was referring to using events as the thread synchronization mechanism. You can find many samples and articles on doing that. Here's one I quickly grabbed from google: http://www.codersource.net/win32_waitforsingleobject.html[^] I'm sure there are several on this site as well.
If you're starting the thread from the dialog's init function, you obviously don't want to hold up that function from completing. There are several ways around this. One very easy way would be to start a timer in the dialog's OnInitDialog function where the timer function could then start the thread as per David's (and the article's) instruction.
|
|
|
|
|
Okay so answer a dumb question. Obviously I don't understand so bare with me.
How will setting things up like you say effect wheither or not my function returns a value.
Thanks.
|
|
|
|
|
There are a couple of ways to do this:
For example...
* You could have a class (CMyWorkerThread)
* CMyWorkerThread could also have a static member function that acts as the thread function (CMyWorkerThread::DoWork)
* Your client code constructs a CMyWorkerThread object and creates a thread passing the CMyWorkerThread member function pointer
* Your client code then blocks on an event that signifies that the thread has finished (e.g., by calling WaitForSingleObject)
* CMyWorkerThread::DoWork processes the work and when done it sets a member variable that represents the return value.
* CMyWorkerThread::DoWork then clears the event
* Once the CMyWorkerThread::DoWork sets the event, the client's call to WaitForSingleObject completes and the client can then access the CMyWorkerThread object's return value member variable
Another way...
* You could have a class (CMyWorkerThread)
* CMyWorkerThread has a constructor that takes a callback function that is stored as a member variable
* CMyWorkerThread has a static member function that acts as the thread function (CMyWorkerThread::DoWork)
* Your client code constructs a CMyWorkerThread object (passing the callback) and creates a thread passing the CMyWorkerThread member function pointer
* CMyWorkerThread::DoWork processes the work and when done it calls the callback function to notify the client that the work is completed and the return code
|
|
|
|
|
how can split an image into 8x8 blocks and calculate the mean,varients.. dct,fft etc.
prabhathgk
|
|
|
|
|
There is Intel mathematical library IPP which implements various functions of Image pprocessing. Check it out on the Intel web site
DavidR
|
|
|
|
|
I need to calculate the (approx) elapsed time between 2 function calls in mSec. MS recommends getting the times in SYSTEMTIME s, converting them to FILETIME s, copying them to ULARGE_INTEGER s and computing their difference. All this seems to work fine. But the MS docs don't indicate the resolution of the difference between the two ULARGE_INTEGER s.
In an experiment, the time taken to execute AfxSocketInit() (i.e. the difference of the low part DWORD s) was 10000. As one would expect, introducing artificial delays caused the delta to increase. But what units am I measuring?
Thanks for any insight.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
struct _timeb tmStart, tmEnd;
_ftime (&tmStart);
foo();
_ftime (&tmEnd);
int nDeltaMSec = (tmEnd.time - tmStart.time)*1000 +
(tmEnd.millitm - tmStart.millitm);
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Hi,
I'm writing some simple image processing functions such as gaussian blur etc. I have an image class to represent the data. I then used the following to benchmark how fast it runs:
<br />
start = clock();<br />
<br />
for (int k = 0; k < 100; k++)<br />
{<br />
}<br />
<br />
<br />
finish = clock();<br />
double duration = (double)(finish - start) / CLOCKS_PER_SEC / 100;<br />
I find that my GetPixel() function is the cause of very slow performance. For example here's the code that I can benchmark:
<br />
for (int i = 0; i < test.m_nHeight; i++)<br />
{<br />
for (int j = 0; j < test.m_nWidth; j++)<br />
{<br />
int value = test.m_pData[i*test.m_nHeight + j]; <br />
}<br />
}<br />
If I access the value directly from the pointer I get duration = 0.0013 s. The other commented line of code gives me 0.012. That's 10 times slower!
I was hoping to wrap everything up nicely in a class, but it looks like that's not going to happen. Is it something I"m doing wrong, or just the way things are for function calls.
Also are there any suggestions you have on code optimization? Any articles? I would not like to start writing messy C code all wrapped up in one function for speed.
Thanks
|
|
|
|
|
Try to use inline function.
Also, check the compiler options, eg. stack checking, optimizations...
Do you build the release or debug version?
The other way is to set on assembly listing in compiler options and compare different solutions of coding.
Indeed, calling a function brings some overhead into your code. You can verify this examining mixed source and assembly listing, if compiler allows this (VC6 does allow). Generally, optimization can be a big problem and there is no perfect and only solution.
|
|
|
|