Skip to content

String encoding in source code #91

@Cirn09

Description

@Cirn09

There are too many potential coding errors in source code
for example:
https://github.com/end2endzone/ShellAnything/blob/master/src/Win32Clipboard.cpp#L42

  static const UINT gFormatDescriptorBinary     = RegisterClipboardFormat("Binary");
  static const UINT gFormatDescriptorDropEffect = RegisterClipboardFormat("Preferred DropEffect");

it only work right when not define UNICODE. And RegisterClipboardFormatA will convert "Binary" to L"Binary", then call RegisterClipboardFormatW.
To improve compatibility, should write like RegisterClipboardFormatA("Binary"), or RegisterClipboardFormatW(L"Binary"),
or more appropriate: RegisterClipboardFormat(TEXT"Binary"))

I tried to modify a part of the code, but I found that this caused coding confusion in the code.
So I recommend ​using TCHAR instead of char, _stprintf_s instead of sprintf_s, TEXT("bala") instead of "bala"

#ifdef UNICODE
 ​#define tstring std::wstring
#else
 ​#define tstring std::string
#endif

or more cpp style

typedef basic_string<TCHAR, char_traits<TCHAR>, allocator<TCHAR> >  tstring;

instead of std::string
(ref: https://stackoverflow.com/questions/36197514/what-is-the-macro-for-stdstring-stdwstring-in-vc)

And define UNICODE and _UNICODE

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions