Search code examples
c++reverse-engineering

Wide strings Visual Studio 2005 vs 2017?


I am trying to hook a function of an old game coded in Visual Studio 2005.

The function uses std::wstring, for some reason the function doesn't read it at all since I am using vs 2017.

I would like to know the difference between both wide strings in Visual Studio 2005 and 2017. And how to use Visual Studio 2005 wide string in Visual Studio 2017?

Note: the hook code is working fine in vs 2005.

Thanks in advance, Best regards.

Update #1: A friend sent me the wide string class from his vs 2005 but still it's missing const wchar_t* constructor

namespace std {
class wstring {
    void *allocator;
    union  {
        wchar_t buffer[8];
        wchar_t* p_buffer
    } _myData;

    int size;
    int reserved_size;
};
}

Solution

  • After some researchers and a help from some friends. I have achieved what I want which is building the old wstring class of vs 2005 with a constructor for const wchar_t* and use it.

    class wstring05 {
        public:
            wstring05(const wchar_t* cstr)
            {
                allocator = nullptr;
                reserved_size = size = wcslen(cstr);
                if (size < 8)
                    memcpy(buffer, cstr, (size + 1) * sizeof(wchar_t));
                else
                    p_buffer = cstr;
            }
    
        private:
    
            void *allocator;
            union {
                wchar_t buffer[8];
                const wchar_t* p_buffer;
            };
    
            int size;
            int reserved_size;
        };