PRB: Error "Cannot Call Friend Function" When You Add a VB DLL to MTS/COM+ Components (282483)



The information in this article applies to:

  • Microsoft Transaction Server 2.0
  • Microsoft COM+ 1.0
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0
  • Microsoft Visual Basic Learning Edition for Windows 6.0
  • Microsoft Visual Basic Professional Edition for Windows 6.0

This article was previously published under Q282483

SYMPTOMS

When you add a Visual Basic dynamic-link library (DLL) that contains classes, which have friend functions, to a Microsoft Transaction Server (MTS) package or COM+ application, you may receive the following error message when you call the method from a Visual Basic client:
Run-time error '97': Can not call friend function on object which is not an instance of defining class

-or-

Run-time error '438': Object doesn't support this property or method
When you call the same method from an Active Server Pages (ASP) page, the following error may be returned to the browser:
The Page Cannot Be Displayed:
Error Type: Freinds (0x800A0061) Can not call friend function on object which is not an instance of defining class /VBProjects/Friends/Test.asp, line 12

-or-

The Page Cannot Be Displayed:
Error Type: Microsoft VBScript runtime (0x800A01B6) Object doesn't support this property or method: 'HelloFriend' /VBProjects/Friends/Test.asp, line 12

CAUSE

This problem occurs because the friend functions (like Private functions) are not part of the COM interface for the Visual Basic class. To verify this, use OLECOM Object Viewer to open the DLL. When you put the components in MTS or COM+, the components' method calls must go through the COM interface. Therefore, a call to the friend functions does not work.

RESOLUTION

There are three ways to work around this problem:
  • Remove the Friend keyword.
  • Put the functions in a BAS module.
  • Set the instancing property of the class that contains the friend function to Private. This way, the class is not a COM component and does not show up in MTS or COM+, and the class can no longer be called from outside the project.

Modification Type:MajorLast Reviewed:5/13/2003
Keywords:kberrmsg kbprb KB282483