title: Convert unsigned long long to wchar_t * and concatenate
body: <p>There are tons of questions on this issue and I have been attempting the various solutions. There seems to be dozens of ways to do this however none of them are working. I am very new to C++ and VS, working for about a month, and I am trying to code an auto Excel program using VC++. I am stuck trying to concatenate a wchar_t * and an unsigned long long. I assume the first step is to "convert" the unsigned long long to wchar_t *. I apologize for throwing in the whole code but I think it may help with showing what I am aiming for and if there are any other weaknesses in the code.</p>
  
  <pre><code>wchar_t * ex(wchar_t * dest, unsigned long long num);
  int main()
  {
  
  unsigned long long num = 10;
  wchar_t *dest= L"A2:B";
  wchar_t * Path=ex(dest, num);
  VARIANT param;
      param.vt = VT_BSTR;
  //      param.bstrVal = SysAllocString(L"A2:B10");
      param.bstrVal = SysAllocString(Path);
  getchar();
  
  return 0;
  }
  
  wchar_t * ex(wchar_t * dest, unsigned long long num)
  {
      // Convert num to wchar_t *
      wchar_t *rangeMax = (wchar_t *)num;
  
      // I think this is used to eliminate extra space in other solutions
      // but not here. It could be useful.
      const int MAX_CHARS = 50;
      size_t count = wcsnlen_s(dest, MAX_CHARS);
      wprintf(L"The length of the string is %ld characters\n", count);
  
      // Throw dest into buf
      wchar_t buf[25] = { 0 };
      int r = wcscpy_s(buf, 25, dest);
      if (r != 0) {
          wprintf(L"wcscpy_s() failed %ld", r);
      }
  
      r = wcscat_s(buf, 25, rangeMax);
  
      if (r != 0) {
          wprintf(L"wcscat_s() failed %ld", r);
      }
      wprintf_s(buf);
      return buf;
  }
  </code></pre>
  
  <p>ex is an edited example from zetcode. I think it is close to being the solution, however when combining buf and rangeMax the code throws all sorts of memory exceptions and fails.</p>
  
  <p>As you can see the final destination for the concatenated wchar_t * is as a BSTR in a VARIANT through SysAllocString.</p>
  
  <p>I appreciate any suggestions on code improvement as well as how to make the code actually run!</p>