|
Hi
I am writing this to help others who will also have the same problem
Creating worker thread :
CWinThread *pThread = AfxBeginThread(&MyThread,(LPVOID*)ptrParam);
MyThread is the member function of CWorker class,
and its prototype is UINT MyThread( LPVOID pParam ) ;
Now while compiling I am getting this error
Error 4 error C2665: ‘AfxBeginThread’ : none of the 2 overloads could convert all the argument types
We know the function prototype is correct.
MSDN ref :
UINT __cdecl MyControllingFunction( LPVOID pParam ); should be the function prototype.
We are also having the Exact prototype , so what could be the problem.
Solution :
All the Class member function will have one hidden parameter ( ie ) this pointer.
So Actucal function prototype of MyThread is UINT MyThread(CWorker pthis , LPVOID pParam ) ;
becoz of this, compiler gives this error.
To Solve the problem
1) Creating one global wrapper funciton around MyThread()
UINT wrapper(LPVOID pParam)
{
CWorker *p = new(std::nothrow) CWorker ;
if(!p)
return ;
p->MyThread(pParam);
return 0;
}
CWinThread *pThread = AfxBeginThread(&wrapper,(LPVOID*)ptrParam); wil work perfectly.
2) Declaring the member function as static
static UINT MyThread( LPVOID pParam ) ;
Note: static member funciton cant access non static member function and non static data member.
Regards,
WindowsPistha
|
|
|
|
|
There's nothing new about this. It's been discussed on this forum dozens of times, and there are even articles about it.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Yes you are right , I have red the below article before i posting.
It did not talk about , why compiler gives error.
so i thought of sharing here,I want to give something back to codeproject which gives lot of information to me.
http://www.codeproject.com/KB/threads/memberthread.aspx[^]
Regards,
WindowsPistha
|
|
|
|
|
|
Thank you Mr. David
here after i will double check before i posting.
Regards,
WindowsPistha
|
|
|
|
|
Can anyone please explain .....
Usually we use Semaphore or Mutex syncronization techniques to avoid deadlock between 2 or more threads.
Now my query is : Is there any other technique for 64 threads to prevent dead lock?
Thanks in Advance
|
|
|
|
|
Number of threads is irrelevant..
You will use same synchronization concepts to prevent deadlocks.
lakshmiyv17 wrote: Is there any other technique for 64 threads to prevent dead lock?
Why so much threads. There will be huge performance hit!!!
Regards,
Sandip.
modified on Saturday, August 23, 2008 12:49 PM
|
|
|
|
|
If you are using that many threads you may want to reconsider your design. This is one of the many reasons you don't see too many Netware servers around anymore. It was common to see millions of threads during primitive indexing tasks while you waited (sometimes hours) for the nightly index clean ups to finish up on Netware Servers. It was a terrible philosophy to create a thread for every little chore or socket.
If you do a search for IO Completion Ports or IOCP here on code project, you'll find some good information on why you want to limit the thread count to be more in line with the number of processing units the machine has to offer.
I hope that helps.
|
|
|
|
|
I am using the following to load a dll in a Visual C++ 2003 project.
LoadLibrary(_T"mydll.dll"));
mydll.dll is generated by a project within the solution although I have to copy it into the exe's location (or change the filepath string) to get it to load. What I want to know is:
1) Is there some kind of mechanism in Visual Studio which can reference the dll via the dll project instead of the filesystem and
2) consequently, what do I need to do to debug code that is executing from that dll project?
I hope I have worded this well enough to get what I'm trying to do across...
|
|
|
|
|
Klempie wrote: 1) Is there some kind of mechanism in Visual Studio which can reference the dll via the dll project instead of the filesystem and
I dont know what do you mean by this..
But
Klempie wrote: 2) consequently, what do I need to do to debug code that is executing from that dll project?
This can be done.
Steps
1. Put break points in the code that you want to debug.
2. Press F5(debug) on your dll project.
3. It will ask you the executable path
4. Browse and specify the path of the exe which uses this dll.
5. Now perform the action on exe that invokes dll functionality.
I hope that makes sense.
Regards,
Sandip.
|
|
|
|
|
Thanks guys. This helped with problem number 2.
|
|
|
|
|
If you want to debug your dll file you can use of breakpoints(and F5) when you will be calling dlls functions of your project use of F5.
|
|
|
|
|
Hi,
I have developed a window based application which is able to fetch the IPAddress but i want the url name of the IPAddress fetched.Can any one tell me how to do it.
The Server is sending the IPAddress.
Thanks In Advance.
Dhiraj Kumar Saini
|
|
|
|
|
Use the Windows socket function getnameinfo().
Regards,
--Perspx
"The Blue Screen of Death, also known as The Blue Screen of Doom, the "Blue Screen of Fun", "Phatul Exception: The WRECKening" and "Windows Vista", is a multi award-winning game first developed in 1995 by Microsoft" - Uncyclopedia
Introduction to Object-Oriented JavaScript
|
|
|
|
|
|
|
I thought this was the Visual C++ / MFC forum....
Aren't jokes better placed in the lounge?
|
|
|
|
|
Hi all
Once again i am asking same question how can i remove .What happen in this code when usb drive is blank then this type of out put come
ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ .
plz help me
BOOL CUSBDlg::FileList()
{
CString acb="";
//Get Logical Drives
DWORD dwDrives=GetLogicalDrives();
if(0==dwDrives)
{
return FALSE;
}
DWORD dwCount=0;
char chDriveLabel='C';
char szRootpath[5]={0,0,0,0,0};
while(dwDrives !=0)
{
if ((dwDrives & 1) != 0)
{
sprintf(szRootpath,"%c:\\",chDriveLabel);
//removable drive
if(DRIVE_REMOVABLE==GetDriveType(szRootpath))
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
//Removable dirve lable
// AfxMessageBox(szRootpath);
m_ListCountries.AddString(szRootpath);
HTREEITEM hRoot1 = m_tree.InsertItem(szRootpath, 0, 0);
//* represent search all files and directories
szRootpath[3]='*';
hFind=FindFirstFile(szRootpath, &FindFileData);
if (INVALID_HANDLE_VALUE == hFind)
{
// return TRUE;
}
// List all the files in the directory .
do
{
//ignore the sub directories
if( _tcscmp( FindFileData.cFileName, _T(".") ) && _tcscmp( FindFileData.cFileName, _T("..") ) )
{
m_ListCountries.AddString(FindFileData.cFileName);
}
}while (FindNextFile(hFind, &FindFileData) != 0);
CFileFind finder;
FindClose(hFind);
}
}
dwDrives = dwDrives >> 1;//next drive
chDriveLabel++;
}
return true;
}
|
|
|
|
|
Hello,
please try using memset before calling FindFirstFile and FindNextFile for FindFileData structure, something like this:
memset( FindFileData, 0, sizeof( FindFileData ) );
hFind=FindFirstFile(szRootpath, &FindFileData);
if (INVALID_HANDLE_VALUE == hFind)
{
}
do
{
if( _tcscmp( FindFileData.cFileName, _T(".") ) && _tcscmp( FindFileData.cFileName, _T("..") ) )
{
m_ListCountries.AddString(FindFileData.cFileName);
}
memset( FindFileData, 0, sizeof( FindFileData ) );
}while (FindNextFile(hFind, &FindFileData) != 0);
CFileFind finder;
FindClose(hFind);
Best regards,
Mihai Moga
|
|
|
|
|
Thx'x it is working...just i want to say greate work for me becouse i havn't found solution of this problem..
Can i ask you some different question related to USB Device..
|
|
|
|
|
Sure, you can ask me, but I do not known too much about USB. You may consider starting a new thread for this ...
|
|
|
|
|
ok no problem i ask here..
[code]How can i show message when any one copy the file or folde from USB Device or Paste the file or folder in USB Device[/code]. Plz help me..
|
|
|
|
|
Mihai Moga wrote: please try using memset before calling FindFirstFile and FindNextFile for FindFileData structure...
Setting that structure to 0 is not necessary.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
vcprog wrote: Once again i am asking same question...
And you've been given the answer three times already. Why do you refuse to comply?
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
ok DavidCrow
Can you give me some pice of code..
Plz help me
Thx,s in advance
|
|
|
|