0

I'm trying to make a thread to handle ZIP archiving:

 HANDLE hThread = CreateThread(
        NULL,
        0,
        ZipProcess,
        (LPVOID) cmdline.c_str(),
        0,
        NULL);

I'm passing the command line argument as a string in the lpParameter.

I keep getting this error:

...argument of type 'void (MyClass::)(std::string) {aka void (MyClass::)(std::basic_string)}' does not match 'LPTHREAD_START_ROUTINE {aka long unsigned int ()(void)}'|

I've tried several things - passing by reference, writing to a buffer, a reinterpret_cast, and others, but the error persists. How to fix this?

Community
  • 1
  • 1
Ben
  • 54,723
  • 49
  • 178
  • 224
  • 1
    It's talking about `ZipProcess` not matching the `DWORD (WINAPI *)(void *)` signature that is required. – chris Nov 13 '12 at 04:02
  • Take also a look here http://stackoverflow.com/questions/331536/windows-threading-beginthread-vs-beginthreadex-vs-createthread-c – David J Nov 13 '12 at 04:15
  • Also note that C++11 has the `` header as well. – chris Nov 13 '12 at 04:17
  • @Fermat2357 - http://msdn.microsoft.com/en-us/library/kdzttdcb.aspx (the _beginthreadex docs) says "This API cannot be used in applications that execute in the Windows Runtime." That sounds like a problem? – Ben Nov 13 '12 at 05:24

1 Answers1

1

You're looking in the wrong spot. The compiler is complaining about the third argument, the thread procedure. Your error looks GCCish, and that says something along the lines of Error passing in argument 3...

To fix it, you need a function signature that actually matches what the function takes (this is an expanded version of the LPTHREAD_START_ROUTINE typedef), namely:

DWORD (WINAPI *lpStartAddress)(LPVOID)

The three problems with your definition are:

  1. Your function does not use the WINAPI (A.K.A __stdcall) calling convention.
  2. Your function has a std::string parameter instead of LPVOID (A.K.A. void *).
  3. Your function is a class member. You need either a static member or a free function in order for it not to expect an additional this argument, causing a signature mismatch.
chris
  • 60,560
  • 13
  • 143
  • 205