Solved

Passing ByRef Variants into a COM Function

Posted on 2002-07-22
4
208 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 200 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

726 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