replacing deprecated atl attribut

4.5k views Asked by At

How should I replace deprecated atl code (Visual Studio 2015 warning C4467)?
The data structure is within a file DataType.h

    struct SData4
    {
        SData4() { Init(); }
        ~SData4() { Delete(); }
        void Init();
        void Delete();
        LPWSTR m_strSomething; 
        [string] LPWSTR m_strCode; 
    };

The IDL file contains method declerations using this structure as follows:

    // interface version 6.0
[
    object,
    uuid(...-.-.-.-.),
    helpstring("IData4 Interface"),
    pointer_default(unique)
]
interface IData4 : IUnknown
{
    [helpstring("method SetData")] HRESULT SetData([in] long lLen, [in, size_is(lLen)] SData4* s);
};

What I don't get is, that there are LPWSTR definitions without [string] attribute within the same struct. And it has worked for a decade :/ The microsoft help page https://msdn.microsoft.com/en-gb/library/8tesw2eh.aspx states that

[string] Indicates that the one-dimensional char, wchar_t, byte, or equivalent array or the pointer to such an array must be treated as a string.

So I have to find a way to tell DCOM that this WCHAR * is a string. But why and how?

Ok, I found an indication within the book "Inside Distributed COM" from Guy and Henry Eddon. They state, that the [string] attribute allows the user to send strings without defining the actual string length. If the attribute is omitted, you have to implement memory management of this string using CoTaskMemAlloc and CoTaskMemFree.

1

There are 1 answers

2
Roman Ryltsov On

To replace [string] or another ATL attribute, the generic solution is to enable Expand Attributed Source option in project settings. Then, when building the code you will have a non-attributed C++ code where attribute processor expanded the attributes. Inspecting the expanded code you see what non-attributed code corresponds to what you had in first place.