|
code:
AfxBeginThread(DoTimer, 0);
error: none of the 2 overloads can convert parameter 1 from type 'unsigned int (void *)'
DoTimer declaration:
UINT DoTimer(LPVOID pParam)
{
....
}
what's wrong? I've seen it from an example.
|
|
|
|
|
change AfxBeginThread(DoTimer, 0); to AfxBeginThread(DoTimer, NULL);
|
|
|
|
|
Josh Gray wrote:
change AfxBeginThread(DoTimer, 0); to AfxBeginThread(DoTimer, NULL);
didn't worked
|
|
|
|
|
sorry my nmistake. Try AfxBeginThread( (AFX_THREADPROC)DoTimer, NULL);
|
|
|
|
|
benjnp wrote:
AfxBeginThread(DoTimer, 0);
works fine as long as I don't call the functions that are built on the same class. Meaning, it can't call other functions or use the variables of that class.
I want to create a thread for a specific function only, of course having the UINT type and (LPVOID param) parameter that may call/use other members of the class. How?
|
|
|
|
|
benjnp wrote:
works fine as long as I don't call the functions that are built on the same class
That's your problem ! You cannot use member functions of a class for that ? Why ? Simply because they have another calling convention than the "standard" functions: the this parameter is passed implicitely as parameter of the function.
A way to have it working: use a global function as callback (instead of DoTimer) and pass the pointer of the current class as parameter (instead of the 0). So like that in your function you will be able to do something like:
UINT MyGlobalFunc(LPVOID pParam)<br />
{<br />
CMyClass* pObject = (CMyClass*)pParam;<br />
pObject->DoTimer();
}
And to start your thread:
AfxBeginThread(MyGlobalFunc,this);
Hope this helps
|
|
|
|
|
Hi,
Try casting the DoTimer to AFX_THREADPROC.
regards,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proff programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
RichardS wrote:
Try casting the DoTimer to AFX_THREADPROC.
How? a very simple snippet will do. Thanx
|
|
|
|
|
AfxBeginThread ((AFX_THREADPROC)DoTimer, 0);
BTW, the reason for the cast is that there are calling symantics between C and C++. The function to create threads needs C calling scheme but the function is a C++ function (even though it is not part of class). By casting it you are not "breaking" anything you are mearly telling the compiler to treat the function as a C function, which it can be.
regards,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proof programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
First off, do NOT take the advice of people who say "Just cast it to "AFX_THREADPROC". The compiler is whining because something is wrong. Casting it just hides that without really fixing the advice. Very very very bad advice.
Have you defined DoTimer inside of a class? If so, then don't. It should be a global function or a static member function in a class.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
benjnp wrote:
error: none of the 2 overloads can convert parameter 1 from type 'unsigned int (void *)'
Cannot convert from type 'unsigned int (void *)' to what? That part of the error message is the key...
AfxBeginThread expects the function you pass to be defined as follows:
UINT __cdecl DoTimer(LPVOID pParam)
{
....
}
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
that's the whole error msg, I'm also looking for it when i first saw it
|
|
|
|
|
If the thread function is a member function it has to be declared 'static'.
Usually when I use worker threads I have one function for starting the thread and one for stopping it, all declared in the class.
Before your app exits you want to be sure that you have no worker threads still running.
Below is a skeleton to build your thread functionality on. You can read more about it in MSDN.
class CTest
{
CTest() { m_pThread = NULL; }
~CTest() { StopThread(); }
.....
protected:
CWinThread* m_pThread;
volatile BOOL m_fStopThread;
BOOL StartThread()
{
StopThread();
m_fStopThread = FALSE;
m_pThread = AfxBeginThread( ThreadFn, this, 0, 0, CREATE_SUSPENDED, NULL );
if( m_pThread )
{
m_pThread->m_bAutoDelete = FALSE;
m_pThread->ResumeThread();
}
return (m_pThread != NULL);
}
void StopThread()
{
m_fStopThread = TRUE;
if( m_pThread )
{
::WaitForSingleObject( m_pThread->m_hThread, INFINITE );
delete m_pThread;
m_pThread = NULL;
}
}
static UINT ThreadFn( LPVOID pThis )
{
return ((Ctest*)pThis)->ThreadFn();
}
UINT ThreadFn()
{
while( !m_fStopThread );
return 0;
}
};
Hope this helps
--
Roger
|
|
|
|
|
You don't have to cast anything!!
<br />
class CMyThread<br />
{<br />
public:<br />
<br />
CMyThread() {};<br />
~CMyThread() {};<br />
<br />
static UINT MyStaticClassBeginThreadProc( LPVOID pParam);<br />
<br />
protected:<br />
int m_iSomeMember;<br />
int m_iThreadState;<br />
};<br />
<br />
UINT CMyThread::MyStaticClassBeginThreadProc( LPVOID pParam)<br />
{<br />
CMyThread *pSelf = (CMyThread *)pParam;<br />
<br />
pSelf->m_iSomeMember = 1;<br />
pSelf->m_iThreadState = 0;<br />
<br />
return 0;<br />
};<br />
<br />
<br />
UINT MyGlobalBeginThreadProc( LPVOID pParam)<br />
{<br />
return 0;<br />
};<br />
<br />
typedef struct<br />
{<br />
int iLen;<br />
int iState;<br />
char cType;<br />
} SOMETHREADDATA;<br />
<br />
<br />
<br />
SOMETHREADDATA threadData;<br />
CWinThread *pThread;<br />
CMyThread thread;
pThread = AfxBeginThread( MyGlobalBeginThreadProc, (LPVOID*)&threadData);<br />
pThread = AfxBeginThread( CMyThread::MyStaticClassBeginThreadProc, (LPVOID*)&thread);<br />
:->
|
|
|
|
|
I tried your idea and it work a bit when accessing a member function of the same class, BUT that member function must be stand-alone. I mean. if I put or access some member variables of the same class, a run-time error occured (MFC4d.dll has an error).
|
|
|
|
|
can u post the declaration of your threads? (that u may have declared in the header file)
V
|
|
|
|
|
I'm currently building a custom control from scratch in Win32 API (no MFC). It's a divder control (something like the MFC splitter).
I defined some notification events to be sent to the parent window like DVN_DELETEDPANE, but I don't know what number to give to the constant. It will be put in NMHDR.code to be sent with WM_NOTIFY to the parent control. I want to know how to define them so they don't conflict with existing values for other controls.
Thank You
David
|
|
|
|
|
this probably won't help you much but you might want to just define your own message instead of using WM_NOTIFY. when MS updates the common controls new constants for NMHDR.code might be added so i don't think there is any way of knowing for sure there won't be any conflicts in the future...
|
|
|
|
|
I understand, but then how to define a custom WM_???? that doesn't conflict with other conrols using WM_USER or WM_APP as I see common controls also use WM_USER + N do define their custom messages.
|
|
|
|
|
the only things i can think of are put
#ifndef divctrl_notify
#define divctrl_notify (wm_app+1)
#endif
in the divctrl header and if it conflicts with other msgs you've defined, define divctrl_notify as something else before you include the header.
a better way might be to just use WM_COMMAND like other windows controls and let the notification codes be anything you want (the notification codes for the different win ctrls seem to all conflict anyway). just make sure you check the id of the ctrl (so you what type of ctrl it is) before parsing the notification codes and there shouldn't be a problem (i think??).
|
|
|
|
|
The problem is that this is a DLL to add support for UI making in another application. The ID of the control is not know to the DLL window procedures, it just parses the correct messages and sends the info back to the calling app through callback support.
Anyways, thanks for the information, I'll see what I can do to get around the problem, I think I have a solution that will work even though there is a conflict.
|
|
|
|
|
ClickHeRe wrote:
The problem is that this is a DLL to add support for UI making in another application
i see. RegisterWindowMessage() might help.
|
|
|
|
|
Read this:
http://blogs.msdn.com/oldnewthing/archive/2009/08/21/9877791.aspx[^]
The two key portions are:
"WM_NOTIFY is basically a sender-defined version of WM_USER"
"It is an unwritten convention that the notification codes for the common controls are all negative numbers. This leaves positive numbers for applications to use for their own purposes."
|
|
|
|
|
Hi,
I will be needing an image ticker (basically, a control that scrolls images from right to left over and over again)for a project that I am starting. I need it to be customizable (speed, specify image paths, ...). I was wondering if anyone knew of any such control that already exists so that I don't have to reinvent.
Of course, since I am posting here, I would prefer if it was written in c++, but since the project is just now about to get on its way, I am also open to the possibility of doing it in c#.
Thanks in advance,
ps: I have already searched for one, but didnt find one. I am posting just in case I missed something, and someone can help.
-----------------
Genaro
\\\|
_ _
@ @
_\\
--|
_/
|
|
|
|
|
Do like that:
Disk ---->Load---->[DIB]
Define a number of vertical bands of the DIB image you want to use
and put consequently those bands to your destination DC using StretchDIBits().
It's fast and ... it works
SkyWalker
|
|
|
|