Reputation: 794
I am using a COM object in VB6. The COM object has a function Foo(Long, Long, Rect). Rect is a struct defined in the COM object implementation. My VB6 code (a button on a form) is like below:
Private Sub btnTestCom_Click()
Set ComObj = CreateObject("ObjectName")
Dim rect As DISPLAY_RECT
rect.Left = 20
rect.Top = 20
ComObj.Foo(101, 0, rect) ' Error here
End Sub
At the last line it is giving me this compilation error: "Only user-defined types defined in public object modules can be coerced to or from a variant or passed to late-bound functions".
Other COM functions that do not have user-defined type parameters are working fine.
How do I solve this problem?
Thanks.
Upvotes: 0
Views: 1038
Reputation: 30398
The function call is late-bound because your variable ComObj
is not typed. You could try declaring it, something like
Dim ComObj As SomeObjectDefinedInComImplementation
EDIT
I would also check that you are actually using the DISPLAY_RECT
from the COM library. Open up the object browser (press F2) and search all libraries for DISPLAY_RECT
.
DISPLAY_RECT
DISPLAY_RECT
with the name of the library Dim rect As TheCorrectLibraryName.DISPLAY_RECT
Upvotes: 1
Reputation: 7196
Assuming DISPLY_RECT is a type, you can't pass types into a public COM method or return a type from a public COM Function in VB6. You will have to make a class duplicating the type, and a helper function that takes the class as a parameter and returns the type.
Upvotes: 0