0
votes

VC++2019 rejects my statement sprintf(subjectId, "%s", imageInfo->name); by error message:

error C2664: 'int _swprintf(wchar_t *const ,const wchar_t *const ,...)': cannot convert argument 1 from 'char [50]' to 'wchar_t *const'

where the type of imageInfo->name is char *, and subjectId is char array (char subjectId[50]).

My VC++ configuration of Character Set is "Use Unicode Character Set". But I must use narrow characters because the message passed to me is in narrow character. As I know, even in case of Wide Character Set, sprintf() can still be used. Besides, I called sprintf(), why does it complain about _swprintf()?

1
Probably Microsoft playing macro games again. I don't have any good documented reason to suggest this, but see what happens if you replace sprintf with _sprintf - user4581301
My addtional comment: Do not use any printf function in C++ - Armin Montigny
Please post the exact code you have in FRV_Dll.cp on line 336. - Chuck Walbourn
@StanHuangatTaiwan The error doesn't happen with that line of code alone, and no one can guess what's different in your real code if you don't post it. See How to create a Minimal, Reproducible Example. For a long shot, does it make a difference if you insert an #undef sprintf before that call? - dxiv

1 Answers

-1
votes

If you select "Use Unicode Character Set", it uses the Unicode character set. C-style strings are now held in TCHAR (which is identical to WCHAR which is identical to wchar_t) instead of char.

If you don't want these transformations, don't ask for them.

You can find more information on the Microsoft page about Unicode and Multibyte Character Set Support.