LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

call a visual basic dll

i'm trying to call an external dll created  in Visual Basic.

im running Labwindows/CVI 7.1 on XP

is this even possible?  i dont have a .h file.


0 Kudos
Message 1 of 13
(4,581 Views)

Yes you can call visual basic dlls from cvi.  This faq may help

http://zone.ni.com/devzone/conceptd.nsf/webmain/1D0C73348D50DE5486256FAF00614757?opendocument

You can use a tool like dependency walker to look into the dll and pull out the information to create your own .h file.  http://www.dependencywalker.com/

Make sure you define your functions as _stdcall so that they handle the stack in the same way as a visual basic program.

0 Kudos
Message 2 of 13
(4,564 Views)
RJohnson,
 
It's true you can use dependency walker to pull out some information from a .DLL, such as function names, but nominally it isn't enough to actually recreate a .h file.  For instance, publically available variables and function parameters cannot be taken from a .DLL using dependency walker.  I think that you will have a pretty tough time recreating the .h file if you don't at least know the two aforementioned things. On the bright side though, CVI makes it relatively easy to use VARIANT data types, which is really what all VB data types are.
0 Kudos
Message 3 of 13
(4,561 Views)
well, unfortunately i dont know much about VB.  

Heres what i've done so far:

I used the "Create ActiveX Controller" wizard from Tools Menu.   Chose the .DLL that I have.  Named a new instrument (.FP) file to be built in my working directory.  Wizard built everything:  a .C file, .H file, .OBJ and .SUB file.

I include the new instrument in my build, and i can (apparently) call the functions as they are listed in the .C/.H files.  

but they dont work like i expect them to.     i dont know if im doing something wrong, or where to begin troubleshooting.


0 Kudos
Message 4 of 13
(4,556 Views)
In order for what you are doing to work, the DLL that you are using must be associated with an ActiveX server on your machine.  Do you know what ActiveX server this is?  Is it a proprietary ActiveX server, or is it COTS?  If it is COTS, what is the name of the .DLL?
0 Kudos
Message 5 of 13
(4,554 Views)
i dont know what it is associated with. 

in the "Create ActiveX Controller" Setup Wizard, the box to select an ActiveX server was greyed out and didnt require/wouldnt accept a server specification.

i thought selecting a DLL was (in some way) a substitute for the server... at least thats how i understood this NI article:

http://digital.ni.com/public.nsf/allkb/AA35D259FD350D3E8625699F0059C641

thanks





0 Kudos
Message 6 of 13
(4,551 Views)
Well, the article is correct in what it says you can do to create an interface to the visual basic DLL.  But in effect VB DLL's are actually ActiveX DLL's and they communicate through a COM interface.
 
What this means for you is that yes, you can use CVI to create some source code that will interface with your VB DLL, but you still need to 'register' you VB DLL as an ActiveX server. 
 
Think of it like this...
 
The DLL itself is simply a black box.  You send data in, the DLL processes the data, and it sends data back, much like a regular C/C++ DLL.  The difference is that with a VB DLL, you have to explicitly tell your windows box, 'hey make this .DLL black box available to me' (you can do this using regsvr32), whereas with C/C++ if the file exists on your system, you can just interact with it.  What you just did with CVI, is you made yourself an interface into that black box.  The .c and .h files arent actually the code within the .DLL per say, they are just a set of functions that you can use to interface with said .DLL.

Once you use your regsvr32 (http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/regsvr32.mspx) you should be able to go back to CVI and the ActiveX controller wizard will have your DLL listed under ActiveX servers.
Message 7 of 13
(4,547 Views)
oh yeah, that did it.

thanks very much for helping me out.

one last question, if you dont mind.   will i still be able to compile an executable for distribution in the normal manner, and have this functionality present, or will the machines running my CVI executable also have to have a server registered for this .dll?

thanks again




0 Kudos
Message 8 of 13
(4,543 Views)

The machine that you distribute your executable to will need your VB .DLL registered in order for your .exe to use it.  If you need to do this you can create a .bat file to distribute with your executable that runs the regsvr32 on your VB DLL, and when you build a distribution kit in CVI (I can only speak for v 7.0+ here ) you can have the CVI distribution kit run the batch file afterwards automatically. 

0 Kudos
Message 9 of 13
(4,542 Views)
great. 

thank you!

Smiley Very Happy

0 Kudos
Message 10 of 13
(4,536 Views)