저는 VB.NET 프로젝트에서 interop dll을 사용하여 MFC 프로젝트의 일부 기능에 액세스합니다.COM interop을 사용할 때 후기 바인딩이 "ByRef 값 형식 매개 변수가 null 일 수 없음"오류를 수정하는 이유는 무엇입니까?
Dim bIsSupposedToWork As Boolean = True
Dim api As API = GetObject(, "MyProject.API")
api.Function1() ' << Function1 returns void, and this works OK
' Function2 returns a long:
If Not bIsSupposedToWork Then
' This next line crashes the application with the message "ByRef value type parameter cannot be null"- error
api.Function2()
Else
' But this works fine:
Dim o As Object = api
o.Function2()
End If
왜?
MFC 클래스에서 DISP_FUNCTION에 대한 반환 값 매개 변수는 VT_EMPTY로 정의되었습니다. VT_I4로 변경하면 먼저 api 객체를 객체 변수에 할당하지 않고 "function2"를 사용할 수 있습니다. 아직 런타임에 바인딩을 사용할 때 완벽하게 실행되는 이유를 모르겠지만이를 수행 할 때 "interop layers in between"에서 런타임 유형 검사를 피할 것이라고 생각하고 있습니다. – Stokke