Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Multithreading? Help!

Multithreading? Help!

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharpc++visual-studioquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    Yonggoo
    wrote on last edited by
    #1

    Hi All, I am studying multithreading with Visual Studio 2005. I have an error with one sample from "Multithreading Applications in Win32 - Jim Beveridge & Robert" 1>.\SearchFile.cpp(44) : error C2664: '_beginthreadex' : cannot convert parameter 3 from 'DWORD (__stdcall *)(void *)' to 'unsigned int (__stdcall *)(void *)' /* SerarhFil.cpp */ #include #include #include #include #include #include "MtVerify.h" DWORD WINAPI SearchProc(void *arg); #define MAX_THREADS 3 HANDLE hThreadLimitSemaphore; char szSearchFor[1024]; int main(int argc, char *argv[]) { WIN32_FIND_DATA* lpFindData; HANDLE hFindFile; HANDLE hThread; DWORD dummy; int i; if(argc != 2) { printf("Usage: %s \n", argv[0]); return EXIT_FAILURE; } strcpy(szSearchFor, argv[1]); lpFindData = (WIN32_FIND_DATA*) calloc(1, sizeof(WIN32_FIND_DATA)); MTVERFY(hThreadLimitSemaphore = CreateSemaphore(NULL, MAX_THREADS, MAX_THREADS, NULL)); hFindFile = FindFirstFile("*.c", lpFindData); if(hFindFile == INVALID_HANDLE_VALUE); return EXIT_FAILURE; do{ WaitForSingleObject(hThreadLimitSemaphore, INFINITE); //HERE MTVERFY(hThread = (HANDLE) _beginthreadex(NULL, 0, SearchProc, lpFindData, 0, &dummy)); MTVERFY(CloseHandle(hThread)); lpFindData =(WIN32_FIND_DATA*)calloc(1, sizeof(WIN32_FIND_DATA)); }while(FindNextFile(hFindFile, lpFindData)); FindClose(hFindFile); for(i=0; icFileName, "r"); if(!ptrFile) return EXIT_FAILURE; while(fgets(buff, sizeof(buff), ptrFile)) { if(strstr(buff,szSearchFor)) printf("%s: %s", lpFindData->cFileName, buff); } fclose(ptrFile); free(lpFindData); MTVERFY(ReleaseSemaphore(hThreadLimitSemaphore, 1, NULL)); }

    Yonggoo

    P 1 Reply Last reply
    0
    • Y Yonggoo

      Hi All, I am studying multithreading with Visual Studio 2005. I have an error with one sample from "Multithreading Applications in Win32 - Jim Beveridge & Robert" 1>.\SearchFile.cpp(44) : error C2664: '_beginthreadex' : cannot convert parameter 3 from 'DWORD (__stdcall *)(void *)' to 'unsigned int (__stdcall *)(void *)' /* SerarhFil.cpp */ #include #include #include #include #include #include "MtVerify.h" DWORD WINAPI SearchProc(void *arg); #define MAX_THREADS 3 HANDLE hThreadLimitSemaphore; char szSearchFor[1024]; int main(int argc, char *argv[]) { WIN32_FIND_DATA* lpFindData; HANDLE hFindFile; HANDLE hThread; DWORD dummy; int i; if(argc != 2) { printf("Usage: %s \n", argv[0]); return EXIT_FAILURE; } strcpy(szSearchFor, argv[1]); lpFindData = (WIN32_FIND_DATA*) calloc(1, sizeof(WIN32_FIND_DATA)); MTVERFY(hThreadLimitSemaphore = CreateSemaphore(NULL, MAX_THREADS, MAX_THREADS, NULL)); hFindFile = FindFirstFile("*.c", lpFindData); if(hFindFile == INVALID_HANDLE_VALUE); return EXIT_FAILURE; do{ WaitForSingleObject(hThreadLimitSemaphore, INFINITE); //HERE MTVERFY(hThread = (HANDLE) _beginthreadex(NULL, 0, SearchProc, lpFindData, 0, &dummy)); MTVERFY(CloseHandle(hThread)); lpFindData =(WIN32_FIND_DATA*)calloc(1, sizeof(WIN32_FIND_DATA)); }while(FindNextFile(hFindFile, lpFindData)); FindClose(hFindFile); for(i=0; icFileName, "r"); if(!ptrFile) return EXIT_FAILURE; while(fgets(buff, sizeof(buff), ptrFile)) { if(strstr(buff,szSearchFor)) printf("%s: %s", lpFindData->cFileName, buff); } fclose(ptrFile); free(lpFindData); MTVERFY(ReleaseSemaphore(hThreadLimitSemaphore, 1, NULL)); }

      Yonggoo

      P Offline
      P Offline
      PJ Arends
      wrote on last edited by
      #2

      Yonggoo wrote:

      1>.\SearchFile.cpp(44) : error C2664: '_beginthreadex' : cannot convert parameter 3 from 'DWORD (__stdcall *)(void *)' to 'unsigned int (__stdcall *)(void *)'

      Yonggoo wrote:

      MTVERFY(hThread = (HANDLE) _beginthreadex(NULL, 0, SearchProc, lpFindData, 0, &dummy));

      Yonggoo wrote:

      DWORD _stdcall SearchProc(void *arg)

      _beginthreadex requires the thread proc that it calls to return an unsigned int. You are passing it a function that returns a DWORD. There is no built in conversion from a DWORD to an unsigned int. Change the return type of the SearchProc to an unsigned int.


      You may be right
      I may be crazy
      -- Billy Joel --

      Within you lies the power for good, use it!!!

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups