encode function fixed

Now try to encode any COMObject