Visual Basic and ActiveX? 33
Dylbert asks: "Putting aside
my gripes about using Microsoft products in the workplace (or
anywhere, for that matter), I was wondering if any Slashdot users
have found ways to overcome the forced use of ActiveX when creating
DLLs in Visual Basic. Because my work uses a few seperate programming
languages to write code in, the use of ActiveX would mean we will
have to convert all our existing code to the same ActiveX
architecture which I believe is unnecessary. Any suggestions?"
I don't use VB, but... (Score:2)
If some queer format is your only choice for DLLs, and your application wouldn't suffer much for lack of shared memory, don't even target DLLs. So long as you can create a stand-alone app, there's nothing to stop you from creating a free-standing application which uses standard Windows message passing to communicate with other applications.
Alternatively, there's nothing to stop one DLL from loading another. If you still need a DLL, you could make a thunking DLL which loads the ActiveX DLL and handles whatever nastiness the ActiveX DLL brings with it, providing a cleaner interface to the user. This should take a supporting Visual C programmer virtually no time at all.
Take a look at... (Score:2, Informative)
Um, just 'uncheck' the dialog (Score:1, Insightful)
Re:Um, just 'uncheck' the dialog (Score:2, Informative)
If you need generic dlls make them ActiveX Dlls & talk to them via COM or use a different language (such as delphi).
VB DLL's areActiveX Only... (Score:3, Informative)
Re:VB DLL's areActiveX Only... (Score:2, Informative)
Most COM/ActiveX objects are easy to use: simply CoCreate the object and start calling the methods. You may have to QI for the appropriate interfaces, but that's no sweat. It's barely harder than using a regular C++ object.
If the object only supports the IDispatch interface, which is probably the case for VB, then things get a little more tedious. Packaging up DISPPARAMS and calling Invoke() is a PITA. Fortunately there are helper classes. MFC has COleDispatchDriver, and the MFC dependencies can be removed, such as with XYDispDriver [codeproject.com].
#import will also build the wrappers for you if you have a typelib.
Re:VB DLL's areActiveX Only... (Score:1)
Caveat 1: Class wizard will not import any public enums from your VB classes into C++.
If you want a standard DLL, you can use the C++ class as a wrapper for the ActiveX DLL.
Caveat 2: You now have the overhead of a DLL that has the overhead of an ActiveX DLL, but if that saves your architecture, it is probably worth it.
You can write a little script to automate the process of creating wrapper class DLLs if you are really tricky.
NOTE: I wasn't that tricky. I used Rational Rose and built a template file in Rose that did a wrapper DLL for me. Rose is a very expensive tool if all you are using it for is to generate wrapper classes.
sorry for the dumb counter-questions... (Score:2, Insightful)
In the meantime, using ActiveX actually opens up a bunch of options, because an ActiveX dll, once created, can be called from within VB, VC++, ASP...
Wait till Feb. 2002 (Score:1)
Re:Wait till Feb. 2002 (Score:2, Informative)
RE: Visual Basic and ActiveX? (Score:3, Informative)
You state that your project will be using different languages, in that case, simply use C for C-style DLLs.
To use those C-style DLLs, simply write Declare statements in VB, just as if you had been making Win32 API calls.
John
The problem... (Score:4, Informative)
1. Just use the VB ActiveX DLL from the other languages using those languages' COM abilities. This makes the most sense, but can it be done in your situation? This has the disadvantage of complicating all the other components of your system that have to talk to the VB components.
2. Build a wrapper around the VB components (probably in C++) such that the other programs/DLLs access the wrapper via straight DLL calls and the wrapper itself talks COM to the VB component. This is not elegant and rates a big "yuck" from me, but it is possible. I don't have any examples for you, but you might find one out on MSDN. Related to the above disadvantage, any component that uses the VB component(s) via this method won't really be complicated by that relationship anymore. On the other hand, you now own a DLL which will contain some very gross code (IMO anyway) because of memory management and COM.
3. Port the VB code to another language that can compile to straight DLLs. IIRC, you can easily port VB to PowerBasic and compile PB down to straight DLLs, which are then accessible to anything. I've never tried this, but my understanding is that it is possible and not too esoteric either. Once you've done this, you can use the PB compiled DLL from VB with the use of the VB Declare statement. Another option along this line would be to port the VB to C/C++. Obviously, that's much more costly, but you could give yourself a nice performance boost and maybe even platform portability to boot.
4. You probably can't do this for several reasons, but I would examine if the languages in question are covered by
That's all I can think of right now. I hope it helps.
A shameless, offtopic plug (Score:5, Informative)
My motivation is that I work for Borland. ActiveX isn't my area, but there's a certain feeling (not only by people who work here!) that our support for ActiveX is better than MS's.
A lot of people prefer Delphi [borland.com] (which uses an OO variant of Pascal [employees.org] in place of VB's pseudo-OO BASIC [digitalcentury.com]) because Delphi produces smaller, faster, and more reliable object files. The differences in syntax take some getting use to, but people who have used both much prefer Delphi for creating ActiveX components. It probably makes a big difference that component architecture is an afterthought in MS's toolset, but a basic part of the Delphi design.
Then for C++ diehards, there's C++Builder [borland.com], which co-exists with Delphi a lot better than Visual C++ co-exists with VB. And there are those who think it supports ActiveX, MFC, and ATL better than VC does. Most of all, C++Builder treats ActiveX components as components, not some weird entity you have to kludge into your app.
Perhaps I can make up for such shameless spamming by suggesting that your real problem is a resistence to component-based programming. This is a powerful programming model, and VB's success is based on its semi-support for it. Perhaps converting your existing code base to this model would improve productivity enough to pay for the conversion.
Didn't anybody read the subject line? (Score:3, Funny)
Stop! Stop! Where will it end!??? (Score:2)
Re:Stop! Stop! Where will it end!??? (Score:2)
Fixed (Score:2)
Re:A shameless, offtopic plug (Score:2)
I agree that Delphi is a better language for some things, but I'll have to strongly disagree with you on this statement.
Component architecture is far beyond being an afterthought for MS.
To put it mildly, Windows is heavily depended on components. To the point where it wouldn't boot without COM. Certainly wouldn't be able to function.
New APIs are now more and more COM interfaces rather than C-style functions. (DirectX is all about COM, frex)
And MS provides some excellent tools (in that, as in pretty much any other development area) for creating compnents.
What kludge are you talking about, for crying out loud?
Re:A shameless, offtopic plug (Score:2)
I should confess that I've never built an ActiveX container app using Visual C++. (I did write a couple of small ActiveX components that way, but that was a while ago.) People who have tell me that it is not easy -- the process is complex and poorly documented. With Borland C++Builder, it's little more than a drag-and-drop operation. That's my basis for comparison.
Re:A shameless, offtopic plug (Score:2)
You should try building an ActiveX in VC6.0
The whole thing is (mostly) wizard-generated boiler-proof code (ATL) which gives you all you can want (and more).
This clears up everything that is related to COM itself and leave you dealing with the bussiness logic you are trying to implement, rather than getting distracted in the details.
Are we talking about the same thing? (Score:2)
As I said before, I don't have any experience with that myself. But users of Visual C++ tell me it's not very easy. I'm only a casual user of MFC, and my knowledge of ATL is superficial. But neither seems very good at using components. Certainly the Microsoft tutorial on the subject (click on Part 6) [microsoft.com] is fairly involved. In C++Builder it's a simple drag-and-drop operation.
Re:Are we talking about the same thing? (Score:2)
You can do it in plain C++, which is indeed unpleasant, or do it via number of handy of smart ways.
#import, frex.
Or CComPtr
ActiveX == COM (Score:2, Interesting)
ActiveX DLLs created in VB look no different to programs than any other DLL created by any other language that creates COM-compatible DLLs.
What _doesn't_ work?
-jbn
CORBA with VBorb... (Score:2)
http://home.t-online.de/home/Martin.Both/vborb.ht
You can write CORBA servers and clients, call EJB's whatever, looks like. Open Source (guy doesn't even offer a binary download). Looks cool, but I haven't even looked at it.
Re:CORBA with VBorb... (Score:2)
--
Evan
Did it in Fortran (Score:1)
YMMV
Been a few years But... (Score:2)
I assume the problem you are having is the fact that for error reporting in VB, it expects an HRESULT and then a call to
How about a little more info about the limitations you are worried about. Are you going from VB to C/ADA/Pascal? And lookingto USE VB as Glue?
What is the problem? (Score:2)
But it's still COM, and COM is totally language blind.
I don't think that you'll find a programming language targeting win32 without some COM binding. It's a must for Win32 programming.
Granted, it may be a bit ugly to work with ActiveX via IDispatch on C (shudder!), but there are ways to go around it with wrappers.