[英]CreateThread string to LPVOID
I'm trying to make a thread to handle ZIP archiving: 我正在尝试创建一个线程来处理ZIP归档:
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
. 我在
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 )}'|
...类型为'void(MyClass ::)(std :: string){aka void(MyClass ::)(std :: basic_string)}的参数与'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. 我尝试了几件事-通过引用传递, 写入缓冲区 ,
reinterpret_cast
等,但是错误仍然存在。 How to fix this? 如何解决这个问题?
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...
您的错误看起来像是GCCish,这表明在Error的意义上传入了参数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: 要解决此问题,您需要一个实际上与功能需要匹配的功能签名(这是
LPTHREAD_START_ROUTINE
typedef的扩展版本),即:
DWORD (WINAPI *lpStartAddress)(LPVOID)
The three problems with your definition are: 您定义的三个问题是:
__stdcall
) calling convention. __stdcall
)调用约定。 std::string
parameter instead of LPVOID
(AKA void *
). std::string
参数,而不是LPVOID
(又称为void *
)。 this
argument, causing a signature mismatch. this
参数,从而导致签名不匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.