Tuesday, July 28, 2009

What is a good way to access a C program from Visual Basic 5.0?

I have been developing a program for doing different types of mathematical analysis in Visual Basic 5.0 because it is compatible with the old MatrixVB tool (for using MatLab functions in VB), but I am finding it slow. There are a couple of places where I'd like to rewrite the code in C and hope it runs faster. I am fairly new to this sort of thing, so if someone could tell me how best to call a C program from Visual Basic, I would appreciate it.





This is needed because VB takes several minutes to do some operations that, using the same algorithm, take only a few seconds in other environments (e.g. MatLab).

What is a good way to access a C program from Visual Basic 5.0?
Run it as a chain command. I forget the exact command, but look it up at http://www.codeproject.com
Reply:Hi,





Take a look at the Shell command.





Something like:


shell "c:\your_path\your_c_program" , vbNormalFocus





Hope this helps!
Reply:You could build the C progrm as a standalone program, then from VB fork another proces to run it, marshall the parameters it needs either on the command line or stdin, then read its output.





Or you could build the C part as a library and link it to your VB program and call functions in it directly (not sure if microsoft's compiler system can do this; I gave up toy languages like VB a long time ago, but .NET can probably do it)


No comments:

Post a Comment