Solved

In ActiveX Control calling functions defined in VB

Posted on 2000-03-04
5
190 Views
Last Modified: 2013-11-20
I want to write an ActiveX control which can call some self-defined subs or functions in vb,I tried, but when never I use the control in vb,it raise the error "automation error".

Here's my code:
//in vc++
TYPEDEF void (CALLBACK* MYPROC)(LPTSTR);

//one method of my control
BOOL DoSomething(long FuncAdd)
{
    ((MYPROC)FuncAdd)(_T("TestString"));
}

//in vb
//sub in a module
sub testsub(a as string)
   msgbox a
end sub

//in a form
sub Command1_Click()
    mycontrol.DoSomething AddressOf testsub
end sub

Could you give me some suggestions?
0
Comment
Question by:ycl
5 Comments
 
LVL 4

Expert Comment

by:inpras
Comment Utility
listening....
0
 
LVL 32

Expert Comment

by:jhance
Comment Utility
Of course this is an automation error since you don't have an automation interface in this VC++ program.

Automation interface is another name for the IDispatch COM interface and you must implement this interface if you want to use it from Visual Basic.

My guess here is that you have no idea what I'm talking about and don't understand how VB works with controls and COM objects.

This might be a good place to start:

http://www.codeguru.com/atl/COM_ATL_Tutorial.shtml
0
 
LVL 11

Expert Comment

by:mikeblas
Comment Utility
inpras, there's no need to announce to the world that you're listening.  Just leave the "Post a comment" box blank, mark the "check here" box, and press the "Submit" button.  You'll be subscribed without firing off an unneeded notification to everyone else.

..B ekiM
0
 
LVL 32

Accepted Solution

by:
jhance earned 100 total points
Comment Utility
So you reject my answer without any comment.  I can only assume you didn't read it...


Of course this is an automation error since you don't have an automation interface in this VC++ program.

Automation interface is another name for the IDispatch COM interface and you must implement this interface if you want to use it from Visual Basic.

My guess here is that you have no idea what I'm talking about and don't understand how VB works with controls and COM objects.

This might be a good place to start:

http://www.codeguru.com/atl/COM_ATL_Tutorial.shtml
0
 

Author Comment

by:ycl
Comment Utility
I have solved this problem,only because I should have declared the parameters of the function in VB using Byval
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

763 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

11 Experts available now in Live!

Get 1:1 Help Now