1

How can I convert the following code to use wcstombs_s instead of wcstombs?

char dbcs[1024];
char *pbstr = (char *)pPropVar->bstrVal;
int i = wcstombs(dbcs, pPropVar->bstrVal, *((DWORD *)(pbstr - 4)));
Frank Martin
  • 3,147
  • 16
  • 52
  • 73

1 Answers1

2
char dbcs[1024];
char *pbstr = (char *)pPropVar->bstrVal;
size_t i;
int err = wcstombs_s(&i, dbcs, 1024, pPropVar->bstrVal, *((DWORD *)(pbstr - 4)));

Note

By the way, you can tell the compiler not to warn about non secure calls:

#define _CRT_SECURE_NO_DEPRECATE
lilezek
  • 6,976
  • 1
  • 27
  • 45
  • Does not work. It says "function does not take 4 arguments" and also says "no instance of overloaded function "wcstombs_s" matches the argument list........... argument types are: (char [1024], BSTR, DWORD, int)" – Frank Martin Oct 07 '15 at 09:45
  • Now this error "cannot convert argument 1 from 'int *' to 'size_t *" – Frank Martin Oct 07 '15 at 09:51