In addition to confusion about Unlock code that in FRM manual section 58,
documentation of EEKEY register, is different from value used in some examples, as explained by cvm.
There is also a mistake in code shown in message #1,
that WREN bit is given the same value two times,
and CMD field is Cleared,
but Not given a value to specify that Write operation is to be performed.
You may try:
EECONCLR = _EECON_CMD_MASK; /* Clear CMD field */
EECONSET = 1; /* Write word command value. */
Shifting the address argument 2 bits left,
will convert a 32 bit word array index into a aligned byte array index, so is a valid translation,
and since interpretation of address argument is not documented neither in FRM example code,
nor in this thread, both alternatives are valid C code.