Solved

Passing ByRef Variants into a COM Function

Posted on 2002-07-22
4
206 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 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…

770 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