|
I need to call the function AfxBeginThread in one of my function (say, myFunc). myFunc should receive a function name which should become a thread.
My code is as follows:
void myFunc(void* fthread)
{
HANDLE cmd_thread;
CWinThread* pCmdThread = AfxBeginThread(fthread, NULL);
cmd_thread = pCmdThread->m_hThread;
..........
}
But i get an error that: cannot convert parameter one of AfxBeginThread from void* to unsigned int(_cdecl*)(void *).....
What should the parameter type be?
|
|
|
|
|
gReaen wrote: myFunc should receive a function name which should become a thread
In your example, you don't provide a function name but a void pointer. What do really need to do ? To provide the name of the function (so, a string containing the function name, like "MyThreadFunc") or a function pointer ?
The first option is much more complicated because there is no way for the compiler to get a function pointer just with its name (its like trying to get a variable with a string containing its name).
For the second option, that's much more easier: you just pass the function pointer that can be passed to the AfxBeginThread.
So, can you be more clear on that point ?
|
|
|
|
|
To expand on what Cedric has said...
Why is MyFunc taking a void? Would it not be a good idea to make the parameter of the same pointer type as AfxBeginThread is wanting? That was you can avoid errors in other places in your code.
This is from VC++6 - The prototype may have changed in later versions, but I doubt it. Just be sure to check.
oid myFunc(AFX_THREADPROC pfnThreadProc, LPVOID pParam)
{
HANDLE cmd_thread;
CWinThread* pCmdThread = AfxBeginThread(pfnThreadProc, pParam);
cmd_thread = pCmdThread->m_hThread;
..........
}
It's rare for me to not pass a parameter to a thread - after all, it needs to know why it exists... Or at least a window handle to post an "I'm done" message.
To answer your next question, functions you pass must have the following prototype to be valid for AfxBeginThread:
typedef UINT (AFX_CDECL *AFX_THREADPROC)(LPVOID);
eg:
UINT AFX_CDECL MyThread (void *)
{
Sleep (10000);
return 97;
}
I hope that helped.
Iain.
|
|
|
|
|
I had to send a function pointer. Thanks for pointing that out.
|
|
|
|
|
Can anyone teach me how to plot a graph using MFC? I have a simple program which plot graph using CPoint. However CPoint can only store integer. The graph size is 150 x 550 but I have over a million points to plot. Any idea?
Thanks
Kennis
|
|
|
|
|
Check my sig, I developed a chart control. I don't know what the performances will be with such number of points but it would be a good test.
Anyway over one million points seems extremly large. Why do you need so much data ? So many points is useless because your screen won't be able to display them all.
|
|
|
|
|
Kennis wrote: I have a simple program which plot graph using CPoint. However CPoint can only store integer.
To implement your own struct (or class) to replace CPoint , such as:
struct FPoint {
float x;
float y;
};<pre>
<blockquote class="FQ"><div class="FQA">Kennis wrote:</div>The graph size is 150 x 550 but I have over a million points to plot. Any idea?</blockquote>
To store all the <code>FPoint</code> objects in a container (such as <code>std::list</code>), and sort it to find out the maximal and minimal values to get the range, in order to normalize it or to shrink it with a multiplier to fit your scale (150 x 550).
<div class="ForumSig"> Maxwell Chen</div>
|
|
|
|
|
Unable to modify / delete my previous reply.
Maxwell Chen
|
|
|
|
|
How do you collapse millions of points into 150 x 550 = 82500 ones?
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.
[my articles]
|
|
|
|
|
CPallini wrote: How do you collapse millions of points into 150 x 550 = 82500 ones?
Maybe he's pushing them reeeeeeeeeeally hard.
Iain.
|
|
|
|
|
There are some overlaps ...
Maxwell Chen
|
|
|
|
|
Kennis wrote: but I have over a million points to plot.
"over a million" doesn't fit in a LONG?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
May be I explain more about what I need to do.
My boss ask me to display the waveform of IR remote control output (like what a CRO is doing ). (The IR code of remote control consists of many carrier pulse). The information of those IR bits is stored in a bin file. Now I am able to get all data from that bin file. But I find difficulties on plotting the data. One bit consists of 2000 carrier pulse and each pulse involves 4 points (one pulse has a high level and a low level). That means one bit consists of 8000 points!!! And the bin file has 127 bits of data... How can I make it.....
I am a C++ beginner, it is so harsh to me...
Anyway, do you think it is possible to plot this graph??
Kennis
|
|
|
|
|
Hmm well the size of an int/LONG is certainly not the problem.
And drawing lines/pixels to the screen is pretty easy.
The problem seems to be coming up with a graphical representation
of the data with a limited number of pixels. I have widescreen
monitors and only have 1680x1050 pixels to work with. You're working
with a much smaller amount, right?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Is the data similar to this[^]?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Yes! This is the data format.
So do you mean the one point occupies one pixel of the screen? If yes, that means it is impossible to show all points in the graph, right?
If it is impossible, I will try to omit the IR carrier details. I will only use 4 points to represent one bit, and not to show the large amount of carrier pulse in a bit.
|
|
|
|
|
// nonrec.cpp -- non-recursive filter design
// NRLowPass() build NR low-pass filter
// NRHighPass() build NR high-pass filter
// NRBandPass() build NR band-pass filter
#include "tools.h"
#include "ltisys.h"
// sinc() or sin(x)/x function
double sinc(double x)
{
if (x==0)
return cos(x);
else
return sin(x)/x;
}
// Create non-recursive low-pass filter by Fourier Transform method
LTISystem NRLowPass(
double freq, // corner freq (fraction of sampling rate)
int ncoeff // # coefficients
) // returns LTI system to specification
{
int i;
// convert frequency
double omega = 2 * PI * freq;
// build half-sized window from sinc function
int nhalf = ncoeff/2;
Waveform hwv(nhalf,1.0);
for (i=1;i<=nhalf;i++)
hwv[i] = omega * sinc(i*omega)/PI;
// window with (half-)hamming window
for (i=1;i<=nhalf;i++)
hwv[i] *= 0.54 + 0.46 * cos(i*PI/nhalf);
// create new LTI System
LTISystem lpfilt(2*nhalf,0);
// copy impulse response into system
// (indexed -nhalf .. 0 .. nhalf)
lpfilt.a[nhalf] = omega/PI;
for (i=1;i<=nhalf;i++) {
lpfilt.a[nhalf-i] = hwv[i];
lpfilt.a[nhalf+i] = hwv[i];
}
return lpfilt;
}
// create high-pass non-recursive filter from low-pass prototype
LTISystem NRHighPass(
double freq, // corner freq (fraction of sampling rate)
int ncoeff // # coefficients
) // returns LTI system
{
// get low-pass version
LTISystem hpfilt = NRLowPass(0.5-freq,ncoeff);
// now modulate with cos(n*PI) = +1,-1,+1,-1,...
int nhalf = hpfilt.a.count()/2;
for (int i=1;i<=nhalf;i+=2) {
hpfilt.a[nhalf-i] = -hpfilt.a[nhalf-i];
hpfilt.a[nhalf+i] = -hpfilt.a[nhalf+i];
}
return hpfilt;
}
// create band-pass non-recursive filter from low-pass prototype
LTISystem NRBandPass(
double lofreq, // low corner freq (fraction of sampling rate)
double hifreq, // high corner freq (fraction of sampling rate) }
int ncoeff // # coefficients
) // returns LTI system
{
// get low-pass prototype
LTISystem bpfilt = NRLowPass((hifreq-lofreq)/2,ncoeff);
// now modulate with cos(n*centrefreq)
int nhalf = bpfilt.a.count()/2;
double cf = 2*PI*(lofreq+hifreq)/2;
bpfilt.a[nhalf] = 2 * bpfilt.a[nhalf];
for (int i=1;i<=nhalf;i++) {
bpfilt.a[nhalf-i] = 2 * bpfilt.a[nhalf-i] * cos(i*cf);
bpfilt.a[nhalf+i] = 2 * bpfilt.a[nhalf+i] * cos(i*cf);
}
return bpfilt;
}
|
|
|
|
|
Perhaps it would help if you told us what's going wrong!
Steve
|
|
|
|
|
|
The results matched against the requirements.
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.
[my articles]
|
|
|
|
|
CPallini wrote: The results matched against the requirements.
You really tested it?!
Maxwell Chen
|
|
|
|
|
Nope. I just suggested the OP the results matched against the requirements will tell what the error is.
Since we don't know both the results and the requirements, we have no chance to.
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.
[my articles]
|
|
|
|
|
Well, as there weren't any requirements mentioned... It exceeded all expectations!
Iain.
|
|
|
|
|
Did you forget the CPMRU (Code Project Mind Reader Unit)?
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.
[my articles]
|
|
|
|
|
Actually the coding is to design a low pass filter to remove ecg signal noise..the coding was given my lecture for the project..when I tried to run it i got this error. ‘fatal error C1083: Cannot open include file: 'tools.h': No such file or directory’
|
|
|
|