Automation error using WinAPI SendMessage call in ActiveX control under VB6.0

Posted on 2004-10-22
Last Modified: 2008-03-17
Hi Folks:

   I am trying to create a simple activeX control consisting of two listboxes. I need to set tab stops in one of the listboxes. I am using the following code in the ActiveX control:

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Any) As Long

Public Sub SetDisplaylistTabs()

Dim TabArray(4) As Long
Dim lcnt As Long

TabArray(0) = 5
TabArray(1) = 20
TabArray(2) = 60
TabArray(3) = 100
lcnt = 4
   SendMessage DisplayList.hwnd, LB_SETTABSTOPS, 0&, ByVal 0&
    SendMessage DisplayList.hwnd, LB_SETTABSTOPS, lcnt, TabArray(0)
End Sub


The second call to "SendMessage" generates the following error:

Run-Time error: '-2147417848 (80010108)'
Automation Error
The object invoked has disconnected from its clients

The above code works fine in a regular VB6.0 program - have tested it. Why is it causing this error in an activeX control?

Any assistance would be greatly appreciated.

Best regards, Dave Melnyk
Toronto, Canada

Question by:d_melnyk
    1 Comment
    LVL 32

    Accepted Solution

    Your declare should be:

    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

    Note that the last parameter should be passed ByRef, not ByVal.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
    Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
    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…

    884 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

    14 Experts available now in Live!

    Get 1:1 Help Now