?
Solved

Passing ByRef Variants into a COM Function

Posted on 2002-07-22
4
Medium Priority
?
211 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 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

800 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