API MacroFeature Security Function. Cannot Get MacroFeatureData Object.

I am writing an application using macrofeatures that is using a COM Server, not a vba macro. everything works great until i try to get the MacroFeatureData object in the security function. Once i call IFeature.GetDefinition, it recursiveley calls itself forever. whats the deal with that. according to the API Help, the security function can get the IMacrofeatureData Object from the supplied Feature Object.

I am assuming i have to tell it not to check for security all of the time but i have to set security based on some values stored in the MacroFeatureData Object.

i have this code in the function to allow temporary disabling of the feature but i really don't like it.

I am just checking the type of MacroFeature that i have defined, then i am seing if it is required as stored in the Parameters.

if it is required then i am returning swMacroFeatureSecurityOptions_e.swMacroFeatureSecurityCannotBeDeleted

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Dim DisableSecurity as boolean = false    

Dim SecurityCheck as integer = 0

Public Function Security(ByVal app As Object, ByVal modelDoc As Object, ByVal feature As Object) As Object Implements SolidWorks.Interop.swpublished.ISwComFeature.Security

        Security = swMacroFeatureSecurityOptions_e.swMacroFeatureSecurityByDefault

        If SecurityCheck > 1 And DisableSecurity = False Then

            DisableSecurity = True

        End If

        If DisableSecurity = False Then

            DisableSecurity = True

            Dim MacFeatData As MacroFeatureData = feature.GetDefinition

            DisableSecurity = False

            SecurityCheck = 0

            If IsNothing(MacFeatData) = False Then

                Dim Req As String = "FALSE"

                Dim FeatType As Integer

                MacFeatData.GetIntegerByName(JEMFeatures.CFeatureType, FeatType)

                If FeatType = JEMEnum.MacroFeatureType_e.Child Then

                    MacFeatData.GetStringByName(JEMFeatures.ChildRequired, Req)

                    If UCase(Trim(Req)) = "TRUE" Then

                        Return swMacroFeatureSecurityOptions_e.swMacroFeatureSecurityCannotBeDeleted

                    End If

                End If

            End If

        Else

            SecurityCheck = SecurityCheck + 1

        End If

    End Function

'''''''''''''''''''''''''''''''

Any ideas on a better way would be great.

SolidworksApi macros