Need help from VB and DLL guru 
Author Message
 Need help from VB and DLL guru

I have a program that I need to write in Visual Basic (VB). This VB
script will execute an external C program. In order to run, VB needs to
pass input variables to the C program and then the C program needs to
pass back the data to the VB script. A quick and dirty way to do this is
as follows.

#1-Have VB write the input variables to a file called "input.dat"

#2-Set up the C program executable to read the file "input.dat", execute
and write to "output.dat"

#3-Excute the C program within the VB script by using the SHELL function
in VB.

#4-Have the VB script read the "ouput.dat" file to process and plot the
data.

Though this works it can suffer from timing problems in that the VB
script will not wait for the C program to finish before moving on to the
next step.

A much better way is to set up the C program as an executable subroutine
that VB can pass arguments into.

I suspect that what we are talking about here is setting up the C
program as a DLL or Dynamically Linked Library and then using the CALL
statement to execute the C subroutine.  Am I correct?

What are the steps to do this?
Does anybody have a very simple example that includes all the steps to
do this?

thanks-Peter Brooker



Sun, 14 Sep 2003 07:24:09 GMT  
 Need help from VB and DLL guru
Maybe I can help you:

First I assume you have the C source code.  Second I assume you have also
basic knowledge and access to the msdn.

You are right when you are saying that the solution is to transform the C
program into a DLL.  To do it you need :
1- A DLLmain function
2- A .def file

The MSDN contain good example of those 2 things.  The DLLmain is very
similar to the WinMain.  If I remember well the declaration is:
int Pascal DLLmain(HANDLE ,HANDLE,LPSTR,int). This method must exist because
it is the method invoked when you load the library.
The .def file is used to "export" your public function.

Now to call those method from VB, you have to use the "declare" keyword.
For example, your DLL is named "mydll" and it export the function
myfunction.  myfunction is declare : BOOL myfunction(int iParam)
Your declare will look like this : Public Declare Function myfunction Lib
"mydll" Alias "myfunction" (ByVal iParam as Integer ) As Boolean
and it will be use like that :  blnResult = myfonction(intParam)

If you look into MSDN, you'll find all the piece you need to complete this
task.  Seach for DLLs to begin.

Hope this help



Sun, 14 Sep 2003 11:08:59 GMT  
 Need help from VB and DLL guru
Von den Tue, 27 Mar 2001 16:24:09 -0700, Peter Brooker

Quote:
> What are the steps to do this?
> Does anybody have a very simple example that includes all the steps to
> do this?

> thanks-Peter Brooker

See http://ppse.org/prog/vbfaq.htm#dll


:)      the Christian Privateer     :) Company: ppse.org
:)          aka Jack Voltz          :) Home page: ppse.org/me
:)   M  A  R  A  N  A  T  H  A  !   :) Prolife: ppse.org/prolife
:) S i e m p r e  P o r   V i d a ! :) Music: ppse.org/music
;)       Pour la Vie, toujours !    :)
;)         Sempre per la Vita!      :)  
;)          Semper Pro Vita!        :)
;)  A L W A Y S   P R O   L I F E ! :)



Sun, 21 Sep 2003 03:25:17 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. I Need superior Guru help with C DLL for VB.

2. Need superior Guru help with C DLL for VB

3. Need Guru Help With C DLL for VB

4. GURU/SEMI-GURU please help with ActiveX DLL threading question

5. Need a DLL guru to help me.

6. *****VB Gurus help needed - Optimizing printing for speed******

7. Need help form VB GURU

8. Serious help needed from VB Gurus !!!!

9. *****VB Gurus help needed - Optimizing printing for speed******

10. Need Help From API Gurus using VB

11. *****VB Gurus help needed - Optimizing printing for speed******

12. ActiveX/VB gurus - desparately need help

 

 
Powered by phpBB® Forum Software