Search code examples
c++identifier

'dim': identifier not found


I am getting this error message:

error C3861: 'dim': identifier not found

Here are my includes:

#include "stdafx.h"
#include "HSMBTPrintX.h"
#include "HSMBTPrintXCtrl.h"
#include "HSMBTPrintXPropPage.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#endif

Here is my function:

#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;
}

As you can see, the two lines that use this are:

dwNSize = dim(szName);

dwCSize = dim(szClass);

Why is that an error?


Solution

  • It looks like you are wanting sizeof:

    dwNSize = sizeof(szName);
    dwCSize = sizeof(szClass);
    

    sizeof returns the number of bytes of the object/variable. However, I just looked at the documentation for the API RegEnumKeyEx, and it needs the number of characters. So I think it actually should divide by the size of a TCHAR (which will be 1 or 2 depending on if your are building for Unicode).

    dwNSize = sizeof(szName) / sizeof(TCHAR);
    dwCSize = sizeof(szClass) / sizeof(TCHAR);