Solved

Passing ByRef Variants into a COM Function

Posted on 2002-07-22
4
202 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
Comment Utility
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
Comment Utility
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 200 total points
Comment Utility
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
Comment Utility
Yep that was it.  
thanks,
Chase707
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now