Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Does anyone know what the ArcObjects reference library is for the IUnknown interface? I migrated the code below into Visual Studio and there is an error on the "Dim pSelItem As IUnknown" line.

ERROR 'IUknown' is not accessible in the context because it is 'Friend'

' Get the selected layer or table
        Dim pTable As ITable
        Dim pDispTab As IDisplayTable
        Dim pStAloneTab As IStandaloneTable
        Dim pSelItem As IUnknown
        pSelItem = m_pMxDoc2.SelectedItem 

I'm guessing I need to provide the full path reference for the Dim line? Maybe there is a newer interface that I can assign pSelItem to for .NET?

UPDATE:

Maybe it should be "Dim pSelItem as Object", since the IMxDocument.SelectedItem Property for .NET accepts Object?

IMxDocument.SelectedItem Property link

share|improve this question
    
This related question would also apply to vb.net. –  Kirk Kuykendall Jun 9 '11 at 15:53

1 Answer 1

up vote 6 down vote accepted

You rarely need to access IUnknown in day-to-day AO development (or COM interop for that matter). Declaring your variable as object will do the trick since you will anyway need to cast it to another interface afterwards.

share|improve this answer
    
thanks for the confirmation! –  artwork21 Jun 9 '11 at 16:05
    
+1 But you can't forget about all COM details - sometimes ReleaseCOMObject is needed, which calls IUnknown.Release behind the scenes. –  Kirk Kuykendall Jun 9 '11 at 16:06
    
@Kirk: I see what you are getting at and agree on your point, but RelaseComObject does actually call IUnknown.Release. CLR manages the RCW's reference counter (conceptually different from COM reference counter) and only if that counter drops to zero, the CLR releases the single reference it holds to the actual COM object. Only then is IUnknown.Release called, but not by ReleaseComObject method, but the CLR interop infrastructure itself. Anyway, these are details developer almost never needs to worry about, but I just wanted to clear that up. –  Petr Krebs Jun 9 '11 at 16:59
    
Yeah, it would be useful to have guidelines for folks migrating VB6 to vb.net. As I recall vb6, it is common practice to set variable = Nothing to trigger IUnknown.Release, but I don't think setting a .net variable to null has the same effect(?) –  Kirk Kuykendall Jun 9 '11 at 17:21
    
@Kirk: it does not have such direct effect in .NET.. COM objects references in .NET are released either via Marshal.ReleaseComObject (or Marshal.FinalReleaseComObject) or when their RCWs are garbage collected. –  Petr Krebs Jun 9 '11 at 17:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.