- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
这是我的测试代码
#include "stdafx.h"
#include "windows.h"
#include "iostream"
using namespace std;
HANDLE hMutex;
static unsigned __stdcall threadFunc(void *params)
{
WaitForSingleObject(hMutex,INFINITE);
printf(":D:D:D\n");
ReleaseMutex(hMutex);
return NULL;
}
int _tmain(int argc, _TCHAR* argv[])
{
hMutex=CreateMutex(NULL,FALSE,NULL);
//first try
unsigned dwChildId;
_beginthreadex(NULL, 0, &threadFunc, NULL, 0, &dwChildId);
//second try
_beginthread(threadFunc, 0, NULL );
WaitForSingleObject(hMutex,INFINITE);
printf("HD\n");
ReleaseMutex(hMutex);
int i;
cin >> i;
return 0;
}
给我 2 个错误:
Error 1 error C3861: '_beginthreadex': identifier not found
Error 2 error C3861: '_beginthread': identifier not found
我正在使用 MFC 作为共享 DLL。我也不知道如何创建两个具有相同功能的线程。
在我包含“process.h”之后
Error 2 error C2664: '_beginthread' : cannot convert parameter 1 from 'unsigned int (__stdcall *)(void *)' to 'void (__cdecl *)(void *)'
最佳答案
_beginthread
和 _beginthreadex
需要不同类型的函数。 _beginthread
需要一个cdecl函数; _beginthreadex
需要一个 stdcall 函数。
在 x86 上,cdecl 和 stdcall 是不同的,您不能同时使用带有 _beginthread
和 _beginthreadex
的单线程过程(在 x64 和 ARM 上,只有一个调用约定,所以 stdcall 和 cdecl 意思相同,不是必需的)。
就是说:不要使用 _beginthread
。相反,请使用 _beginthreadex
,并确保关闭它返回的句柄。 The documentation充分解释了 _beginthread
的缺点以及为什么 _beginthreadex
更可取。
关于c++ - _beginthread/ex C3861 - 找不到标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17068914/
所以,我有一些问题,我怀疑内存泄漏,为了测试我写了这段小代码。通过注释以下行: printf("Calc index: %d\n", ArrLength); 代码运行良好。但是当我取消注释时,程序在几
鉴于情况: class A {}; class B : A; B b; 如果 class A 的默认构造函数使用 _beginthread 创建线程,该线程是否有可能在 class B< 的构造函数之
我一直在我的 (windows) C++ 类中使用 _beginthread 来创建线程。据我了解,要使用 _beginthread 并在类中传递成员函数,必须遵循一个相当迟钝的包装协议(protoc
我想在c代码中调用go方法 操作系统是windows10 我使用 Cygwin64 终端 main.go package main import "C" func main() {} //export
我有以下代码来启动一个新线程 int number = 10; _beginthread(ModbusReadWrite, 0, (void*)number); 函数是: void ModbusRea
我想将 int 变量传递给线程。 我的线程代码: void record_WAVthread(void* data) { int channelId = *(int*)data; co
Windows 中的 CreateThread 和 beginthread API 有什么区别?哪个更适合创建线程? 最佳答案 早期版本的 Microsoft CRT 需要 _beginthread(
我正在实现一个启动 4 个线程的程序。 函数是: void* SOURCE_in(struct SOURCE_1*); void* SOURCE_out(struct SOURCE*); void*
我正在创建一个双线程数组求和程序,我正在使用 windows.h 线程。这是我目前拥有的代码。 #include "StdAfx.h" #include #include #include #i
我有这段代码,但没有得到预期的结果……怎么了? typedef struct { int data1; int data2; }t; void foo(int a, int b) {
我有一台用 C++ 实现的服务器,运行在具有 25GB RAM 的 Windows 2003 企业版上。 在压力测试期间,我看到当它试图通过调用 _beginthread 创建一个新线程时,我得到了
函数中_beginthread , 第二个参数 (stack_size) 是什么意思? 堆栈大小在哪里?默认值 (0) 是什么意思? 最佳答案 堆栈大小在哪里? 调用栈是一个stack维护有关执行软件
这是我的测试代码 #include "stdafx.h" #include "windows.h" #include "iostream" using namespace std; HANDLE hM
是否可以为使用 _beginThread 创建的线程分配名称?我没有使用此功能的选择,但我试图密切关注哪些线程正在关闭,当我没有关联的名称时,这可能会造成混淆。 最佳答案 这是您要找的吗: MSDN:
我正在尝试为我正在制作的游戏建立一个 UDP 连接,套接字的输入是通过第二个线程读取的,因此游戏可以在等待消息时继续运行。我让它在一个单独的项目中工作,但是当把它移植到我的游戏代码时,我得到一个未解析
我尝试用 C++ 编写多线程 WIN32 应用程序,但由于我遇到了困难。其中一个窗口过程创建了一个线程,它管理这个窗口的输出。如果此窗口过程收到一条消息(来自其他窗口过程),它应该将其传输到它们的线程
我是线程和 Winforms/C++ 的新手。当我按下一个按钮时,我想在一个新线程中启动一个函数。我一直在关注这个 tutorial对于线程。当我在单独的 VC++ 项目中构建该站点上给出的示例代码时
我要执行上述操作。 void myFunc(void *parameters) { myObject myObj = // Here I would like to receive the ob
1)这篇文章的答案WaitForSingleObject : how to get handle from _beginthreadex说只有将 uintptr_t returned _beginth
我是第一次尝试使用 Windows(在 VS2010 中)的线程库。但我想我遗漏了一些东西......我如何加入创建的线程?当线程仍在运行时,如何防止 main()-Programm(或其他“高级”函
我是一名优秀的程序员,十分优秀!