At first glance, the only potential issue I see is the layerName buffer is small, consider using _tcscpy_s over _tcscpy
BTY, this coding style is analog to how you would do this in old style ADS. There are better, more modern ways to do this using AcDbEntity’s methods
AcDbEntity::setLayer (AcDbObjectId, Adesk::Boolean, bool) or AcDbEntity::setLayer (ACHAR*, Adesk::Boolean, bool)