?
Solved

Passing ByRef Variants into a COM Function

Posted on 2002-07-22
4
Medium Priority
?
219 Views
Last Modified: 2010-08-05
I have an ActiveTemplateLibrary DLL written in C++

One of the objects has a function defined in IDL as:

HRESULT GetInfo([in] int iMaxSize, [out] VARIANT* info, [out] int* iNumResults);

The problem is when I call the function in VB:
...
Dim info as Variant
Dim iNum as Integer

Set objIAdmin = New AdminObject

' the following line gives runtime error 13 (type mismatch)
objIAdmin.GetInfo(500, info, iNum)

' do stuff with data

Set objIAdmin = null
...


Why am I getting a type mismatch error on the GetInfo function?
0
Comment
Question by:Chase707
4 Comments
 
LVL 3

Expert Comment

by:Hornet241
ID: 7170689
Try this

Dim info as Variant
Dim iNum as Integer
Dim iMaxSize as Integer

Set objIAdmin = New AdminObject
iMaxSize = 500
' the following line gives runtime error 13 (type mismatch)
objIAdmin.GetInfo(iMaxSize, info, iNum)

' do stuff with data
0
 
LVL 2

Expert Comment

by:corvanderlinden
ID: 7171121
Try this

Private Declare Function GetInfo Lib "yourlibWithPath" _
    (ByVal MaxSize as Long, info As Any, NumResults As Long) As Long
0
 
LVL 26

Accepted Solution

by:
EDDYKT earned 800 total points
ID: 7171656
I think corvanderlinden is right. Use long instead


Dim info as Variant
Dim iNum as long
Dim iSize as long

Set objIAdmin = New AdminObject

iSzie = 500
' the following line gives runtime error 13 (type mismatch)
objIAdmin.GetInfo(iSize, info, iNum)

' do stuff with data

Set objIAdmin = null
0
 
LVL 4

Author Comment

by:Chase707
ID: 7172495
Yep that was it.  
thanks,
Chase707
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question