简体   繁体   中英

Access violation writing on platform toolset v140 DLL when call from v100

I have a DLL written in VS2015, with platform toolset: Visual Studio 2015 (v140). this DLL include the following function:

std::string GetUserPoints(std::string ownerid);

I have created a win32 console application by visual studio 2010, and tried to call this "GetUserPoints" function!

I get a runtime access violation when GetUserPoints aim to return the string value.

I tried to change this GetUserPoints to:

int GetUserPoints(std::string ownerid, char*& output)
    {
        if (l_RestLowLevel != NULL) {
            std::string str = utility::conversions::to_utf8string(l_RestLowLevel->GetUserCameraPoints(utility::conversions::to_string_t(ownerid)));

            // Dynamically allocate memory for the returned string, +1 for terminating NULL

            output = new char[str.length()+1];

            // Copy source string in dynamically allocated string buffer
            strncpy_s(output, str.length() + 1,  str.c_str(), str.length());

            return str.size();
        }
        return 0;
    }

But I get a runtime "Access violation writing" exception on:

output = new char[str.length()+1];

All versions of Visual C++ have their own implementation of the strandard library ,which are not necesarilly the same ,in fact they're highly likely to be different.

Due to incompatibillities its recommended not to specify Standard library elements in your DLL interfaces.

Internally in your Programs and or Dll's you can use them without problems. but when interfacing with each other you have to agree on the implementation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM