How to get a MeshComponent from a SocketName?

Hello, I am attaching a static mesh to a skeletal mesh (the Pawn Mesh), using the AttachTo function.

TheStaticMeshComponent->AttachTo(MyPawn->GetMesh(), MyWeapon->SocketName, EAttachLocation::SnapToTarget);

I want to retrieve the variable TheStaticMeshComponent using the SocketName through the MyPawn->GetMesh, could you help me explaining a proper way to do this?

I found a function that looks helpful, but don’t know how would that be configured using the AttachTo and also it seems to be used for GC,

PlayerCharacter->GetComponentsByTag(MyClass, "MyTagName");