"dim":找不到标识符
'dim': identifier not found
我得到这个错误信息:
错误C3861: 'dim':标识符未找到
以下是我的内容:
#include "stdafx.h"
#include "HSMBTPrintX.h"
#include "HSMBTPrintXCtrl.h"
#include "HSMBTPrintXPropPage.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
下面是我的函数:
#define MSS_PORTS_BASE _T("Software\Microsoft\Bluetooth\Serial\Ports")
bool FindBluetoothPort(TCHAR name[16]) {
HKEY hKey, hRoot;
TCHAR szPort[20] = _T(""), szPortString[20];
DWORD len, dwIndex=0;
bool bFound=false;
INT i = 0, rc;
DWORD dwNSize;
DWORD dwCSize;
TCHAR szClass[256];
TCHAR szName[MAX_PATH];
FILETIME ft;
hRoot = HKEY_LOCAL_MACHINE;
if (RegOpenKeyEx (hRoot, MSS_PORTS_BASE, 0, 0, &hKey) != ERROR_SUCCESS) {
rc = GetLastError();
return 0;
}
dwNSize = dim(szName); <---- ~~ !! HERE IS THE LINE THAT ERRORS
dwCSize = dim(szClass); <---- HERE IS THE LINE THAT ERRORS !!
rc = RegEnumKeyEx (hKey, i, szName, &dwNSize, NULL, szClass, &dwCSize, &ft);
while (rc == ERROR_SUCCESS)
{
// how many children
TCHAR szCurrentKey[MAX_PATH];
wcscpy(szCurrentKey, MSS_PORTS_BASE);
wcscat(szCurrentKey, TEXT("\"));
wcscat(szCurrentKey, szName);
wcscat(szCurrentKey, TEXT("\"));
len = sizeof(szPort);
if(RegGetValue(hRoot, szCurrentKey, _T("Port"), NULL, (LPBYTE)szPort, &len)) {
wsprintf(szPortString, _T("%s:"), szPort);
bFound = true;
break;
}
dwNSize = dim(szName);
rc = RegEnumKeyEx(hKey, ++i, szName, &dwNSize, NULL, NULL, 0, &ft);
}
if(bFound)
_tcscpy(name, szPortString);
return bFound;
}
如您所见,使用这个的两行是:
dwNSize = dim(szName);
dwCSize = dim(szClass);
为什么这是一个错误?
看起来你想要的是sizeof
:
dwNSize = sizeof(szName);
dwCSize = sizeof(szClass);
sizeof
返回对象/变量的字节数。然而,我刚刚查看了API RegEnumKeyEx的文档,它需要字符的数量。所以我认为它实际上应该除以一个TCHAR的大小(这将是1或2取决于你是否正在为Unicode构建)。
dwNSize = sizeof(szName) / sizeof(TCHAR);
dwCSize = sizeof(szClass) / sizeof(TCHAR);
你想要sizeof
。
如果你最初学习了dim
,那可能是一个真正在幕后调用sizeof
的宏。
我过去使用过以下宏:
#define DIM(x) (sizeof(x)/sizeof((x)[0]))
它不是由任何标准包含提供的,您必须自己定义它。
你也可以使用模板函数做一个更现代的版本:
template<typename T, size_t N>
size_t dim(const T (& array)[N])
{
return N;
}
相关文章:
- 设置 Visual Studio for MPI: 找不到标识符错误
- 找不到标识符合并
- 在 c++ 中找不到此函数的标识符
- 从子类访问模板类成员时出现"找不到标识符"错误
- std::p opcount 标识符在 MSVC 16.6.0 中找不到
- OpenCV 3 错误"CV_FOURCC":找不到标识符
- C++ ATL | 找不到_InternalQueryInterface标识符
- im调用函数时找不到标识符?
- clock_gettime:在 Windows 10 的 Visual Studio 中找不到标识符
- 英特尔 TBB - "初始化关键部分 Ex":找不到标识符编译器错误
- 找不到标识符.C3861
- 找不到睡眠标识符 Visual Studio 2017
- 在void tryagain()上找不到标识符
- 找不到内存集标识符
- 在C 类中找不到标识符
- 找不到标识符,尝试在 C++ 中显示数组值
- 找不到QT 5.6 update()函数标识符
- 我遇到:错误2错误C3861:"fx":找不到标识符
- 找不到加载着色器标识符
- OpenGL - 'glTexSubImage3D':找不到标识符