简体   繁体   中英

error code WFP: State Error (active) E0513 a value of type “const wchar_t *” cannot be assigned to an entity of type “wchar_t *”

I am using Visual Studio Community 2019, SDK & WDK preview.

E0513 a value of type "const wchar_t *" cannot be assigned to an entity of type "wchar_t *".

How to fix it?

SubLayer.displayData.name = L"APPDinsFirewall";
SubLayer.displayData.description = L"APPDinsFirewall";

Code WFP below:

DWORD AppFilter::appBindInterface() {

    DWORD ErrorCode = ERROR_BAD_COMMAND;
    //RPC - Remote Procedure Call status Gọi hàm thủ tục từ xa
    RPC_STATUS rpcStatus = {0};
    //Sublayer structure
    //FWPM_SUBLAYER0 SubLayer = {0};
    FWPM_SUBLAYER0 SubLayer;
    memset(&SubLayer, 0, sizeof(SubLayer));
    //Tạo một GUID cho SubLayer
    rpcStatus = UuidCreate(&SubLayer.subLayerKey);
    if (rpcStatus == NO_ERROR) {
        /* Lưu GUID để sử dụng sau này. 
        Sao chép bộ nhớ từ SubLayer sang appsubGUID từ size của subLayerKey
        */
        CopyMemory(&appsubGUID, &SubLayer.subLayerKey, sizeof(SubLayer.subLayerKey));
        //Gán thông tin trong SubLayer
        SubLayer.displayData.name = APP_SUBLAYER_NAMEW;
        SubLayer.displayData.description = APP_SUBLAYER_NAMEW;
        SubLayer.flags = 0;
        SubLayer.weight = 0x100;
        //Add SubLayer
        ErrorCode = FwpmSubLayerAdd0(appEngineHandle, &SubLayer, NULL);
    }
    return ErrorCode;
}

E0513 a value of type "const wchar_t *" cannot be assigned to an entity of type "wchar_t *"

If you're certain that the other code won't write into it, you can cast the constness away with const_cast<wchar_t *>(APP_SUBLAYER_NAMEW) , if the code does write into it later, your program will crash.

Or you could make a writable duplicate of the string with something like _wcsdup , you should also not forget to deallocate it later.

Or you could store the string in a wchar_t array in global or static scope. Not a local variable, that would crash in interesting ways as well.

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