• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3038
  • Last Modified:

Convert ActiveX DLL to OCX Control

Someone is using Matlab which supposedly will not accept my ActiveX DLLs -- it only accepts ActiveX Controls (OCXs). Provided that is true, is there an easy way to wrap my DLL inside an OCX without having to do a lot of work?

I also need to keep them separate, as legacy software uses the DLL. The DLL had to run in-process and be fast (i.e., little overhead) which is why the DLL was chosen over EXE or OCX.
0
GivenRandy
Asked:
GivenRandy
  • 5
  • 4
1 Solution
 
PaulHewsCommented:
Basically it will consist of creating a new usercontrol project, running the interface wizard to create some basic control properties and copying your DLL class code into the usercontrol.  
0
 
PaulHewsCommented:
Of course maintenance becomes a pain if you change that class... Maybe better to add that class to the OCX project and delegate all the properties from the OCX.  In other words the OCX creates an object based on the class and calls each property/method from similarly named properties/methods.
0
 
GivenRandyAuthor Commented:
The latter is what I expected. More input will be appreciated.

p.s., this is VB6.

p.p.s., PaulHews: long time, no see!
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
phildaleyCommented:
Without trying it, I would have thought you would write a UserControl that has all the same methods (subs and functions) and properties of the DLL. The UserControl would just delegate or call the DLL routines. You could then keep the DLL as it is and supply and register it as part of the installation.

For example, suppose your DLL was called MyData and it had a class CCustomer that had the following method:
Public FindName(sName as string) as Long
    ' Find customer ID whose name is sName
    .
    .
   
end sub

You would then code a method into the UserControl such as:
Public CustomerFindName(sName as string)
    Dim cCust as MyData.CCustomer
    set cCust = new MyData.CCustomer
    CustomerFindName = cCust.FindName(sName)
    set cCust = Nothing
end sub

Repeat for each method/property of the MyData DLL which you want to expose from the UserControl.
0
 
GivenRandyAuthor Commented:
PaulHews, that was the original plan and what, unfortunately, I probably will have to do.
0
 
PaulHewsCommented:
If it represents a lot of work to do the delegation code manually, you could probably write a program that goes through the cls file, picks out all the public properties/methods and writes the delegation code for you.

>long time, no see!

Yes, nice to see a familiar face. :) Hope things are good for you.
0
 
GivenRandyAuthor Commented:
PaulHews, I finally go to this phase on the other project (funny how projects and task shift around here). It took about 30 minutes to do just that and it worked well as an OCX on other projects. Turns out that MATLAB will not allow pass-by-reference, so some of the functions may have to be re-written, which may be a pain. If you know any more about this, I can give more points or open another question.
0
 
PaulHewsCommented:
You're using matlab com builder?  Sorry, don't know much about it.  
0
 
GivenRandyAuthor Commented:
I will try to keep posting comments here for archival purposes. Supposedly 6.5 (r13) will handle this, which we are using. Our initial attempt at it failed, but we will be contacting MathWorks (which should fall under our maintenance fee with them, which is pricey, but useful). They did have one post about it, but as I mentioned, we got an initial error:

http://www.mathworks.com/company/digest/march03/activeX.shtml
0
 
GivenRandyAuthor Commented:
The pass-by-reference does work for most cases, now. Mathworks is still investigating why it does not work for 1) array of strings and 2) when called function uses Redim Preserve (which does not make sense because it does allow for Redim). If you have ANY comments on this, please make them at:

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20683152.html
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now