Integrating a Visual Basic Component with Coldfusion

So one of the tasks I’ve been given this week is to find out of I can leverage a propriety dll with Coldfusion to examine the inside of some proprietary CAD objects and return information about them.  The DLL itself came with a Visual Basic project.

 

Thing is, I haven’t touched Visual Basic since … 1998?

 

Yep. It’s been a while. That was VB version 4, I believe. Or 3.  Or I don’t know.  Distant past, whatever it was.

So my first step was to download Visual Studio 2013 Community Edition to my unsuspecting Macbook Pro. I have Windows 8.1 and Windows Server 2012 installed in separate virtual machines, so VS went onto the Windows 8 install.

 

2 hours to install, and it reported errors, and the IDE wouldn’t start.  So, I repaired the installation, and now we’re fired up. I’m in an IDE, but I’ve never actually used it, so my first step is to see if I can get a look at the DLL and its interfaces.

 

Ooohhh…. I found something called the “Object Browser.”  Let’s find out if this will do it.

Screen Shot 2015-03-24 at 10.10.36 AM

Excellent. I browse to my component in the object explorer and book, I’ve got some visibility into the object.

Screen Shot 2015-03-24 at 10.14.14 AM

Next step… we’ll see if we can instantiate that guy in Coldfusion. Time to fire up Windows 2012.

Now my poor laptop is starting to groan. I’m running eclipse and windows 8 and visual studio and windows server and coldfusion server and iTunes … you get the point. But here’s the key thing. It is running :)

Here’s the code in my OnRequestStart method:

Result?

Screen Shot 2015-03-24 at 10.22.57 AM

Class not registered. Plus, over in Windows 8.1, we’re getting complaints about low memory.  I’m going to close out Visual Studio, because for the moment I have the answers I needed over there, which was the namespace and the name of the class. Which isn’t registered.  Whatever that means.  I’m not a Windows programmer, so I’ve got a lot to learn here. I paste the message into google, and the first link is an ancient article over on Adobe’s website, referencing this error and giving instructions on how to register a dll.  We’ll give this a try. I browse to my dll and follow the instructions.

Hmmm… error message. Probably because that article was 50 years old, and I’m working on Windows 2012.

 

Screen Shot 2015-03-24 at 10.33.07 AM

Ho hum. HOURS later, I still haven’t solved this one, though I think I’m zeroing in on the problem.  Trying to use the regasm tool to register the DLL, which in theory should work, but in practice is not.

Success!

Until I get the same error: AutomationException: Class not registered.

 

Gah!!!! See, I’ve never worked with COM objects in Coldfusion. Plus I’m new getting back into Coldfusion after a several year hiatus.  I finally, finally got some traction though when I learned that … uh oh … coldfusion 64bit doesn’t even support COM objects. And that’s partly because Microsoft isn’t really supporting them any more.  Which leads me to how do instantiate the thing? I looked at some more examples, then tried this:

Why did this code work when the other didn’t?  A couple of key things.  First, before I was trying to instantiate a COM object, not a dotNet assembly.  The distinction is in how Windows does things, and while it’s a matter for curiosity and future understanding, it’s outside the scope of my work now.  Second, I needed to give the full NAMESPACE of the component, which was helpfully not defined in the documentation. I did, however, find the namespace by opening the thing in Object explorer in Visual Studio. Namespace – CadXLib  Class: CadX

 

CFDUMP now gave me a nice picture of all of the methods inside the class.

Leave a Reply

Your email address will not be published. Required fields are marked *