Discussion Locked

Linking VB and C

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
What is the best way to link C and VB. I know that it can be done using the command shell. But I face some problem with that. My problem is that until the exe file is excuted i cannot proceed to the next statement in vb code. I want make sure that before the next statement is executed (in the VB code) the exe file is completely run. I did it by putting a loop between the statements but again this depends on the system speed and load. It can fail sometimes.Please suggest me a solution to this.

7 replies

by jackofalltech

Are you trying to run another program from within a VB program? Is the other program cmdline-only or is it a Windows program?

There are many VB specific sites on the 'net. I have seen several articles on how to wait for another program to finish before continuing the current one. Do a little research.

Ralph

by ram_cv

There could be quite a few methods to achieve this goal:

1) In your C program create a predefined file at a predefined directory. This file should be created when the C program exits. In the VB program check for this file's existence in a loop and proceed further only when the file is created.

2) Use Windows messages. In your C program when you are finished and are going to end, send a Windows message to the VB program. The VB program should be doing a doEvents and waiting for this event.As soon as it recieves this event it should go ahead with its processing.

Also there are other methods of IPC like sockets which can be used for this purpose, but one the above two should be the most suitable for your purposes.

Cheers!
Ram

by ram_cv

In VC register a windows message, I think there is an API call called RegisterMessage. Then subclass your VB application to listen for that Message. Then do a PostMessage from VC to post that message for the VB application to wakeup.

by sygnosys

The best way to link C and VB, in my opinion, is through a DLL. Just pick up your C code and build a DLL from it!
But if you want to stick with an independent exe
you can use the shell function and simply state in the 3rd parameter true and this will make shell function sync with the execution of your exe.

This discussion is closed to new replies.