Microsoft KB Archive/282483

= PRB: Error &quot;Cannot Call Friend Function&quot; When You Add a VB DLL to MTS/COM+ Components =

Article ID: 282483

Article Last Modified on 5/13/2003

-

APPLIES TO


 * Microsoft Transaction Services 2.0
 * Microsoft COM+ 1.0
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 6.0 Professional Edition

-



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.

Additional query words: runtime 97 438 0x800A0061 0x800A01B6

Keywords: kberrmsg kbprb KB282483

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.