Can you use std :: string in a third-party dll?

I have been looking for answers to my problems, but it seems that most people are interested in passing std :: string across .dll borders. But I'm more interested in using std :: string in a class that is in the DLL that I am creating.

I am releasing my .dll (via email) to a group of people in a forum where I am single, so my question is: can you use std :: string in a .dll without having restrictions, such as a compiler, that should be the same same, version, CRT should be the same, etc.

Can you give examples of what is unsafe and what is safe?

Example: Was it safe to use the “bootloader” to use the SetSender function?

Mail.h

class _declspec(dllexport) Mail {

    struct ENVELOPE {
        std::wstring SenderEmail; //Should the type be LPWSTR or can it safely be std::wstring
        LPWSTR SenderName;

    }Envelope;

public:
    int SetSender(LPWSTR SenderEmail);
    Mail();
    ~Mail();

};

Mail.cpp

#include "stdafx.h"
#include "Mail.h"

int CoffeeBeans::Mail::SetSender(LPWSTR Email) {
 //Pass LPWSTR instead of std::wstring across .dll boundary

    if (Email == nullptr || lstrcmp(Email, L"") == 0) {
        throw L"Email was either nullptr or empty.";
    }

    this->Envelope.SenderEmail = SenderEmail;
    return 0;


}
+4
1

, LPWSTR wchar_t*, .. , DLL- ( , , ..). std::string , DLL CRT. , ( , ). CRT-, DLL dll CRT (, Oracle OCCI). , ++.

+2
source

Source: https://habr.com/ru/post/1658645/


All Articles