
     A Statically Linked DLL Example


 A statically linked DLL is much easier to
 call than a DLL that is loaded dynamically.
 The VB runtime is an example of a statically
 linked DLL.

 This is the original post on Egroups by Kye.


 -------------------------------------------
 The file BUILD.BAT automates this example.
 -------------------------------------------


From: Kye  <sky1@biosys.net>
Date: Sat Oct 7, 2000 9:56am
Subject: Re: [BCX BASIC TRANSLATOR] Re: DLL's


Hi Bob, I hope this is what you are looking for.

Here is a small exported function that takes 2 params
(you can have more).


$DLL
Function MyProc$ (pString$, pInt%) EXPORT
Local x%
Local RetString$
For x% = 1 To pInt%
  RetString$ = RetString$ & pString$
Next x%
Function = RetString$
End Function

I saved this as myproc.bas.

Here is the batch file I use to translate and compile dlls:

@bc %1
@c:\lcc\bin\lcc %1.c
@c:\lcc\bin\lcclnk -s -dll -subsystem:windows %1.obj
@del %1.obj
@del %1.exp

There will also be an import library (.lib) file generated
during compilation along with the dll.


The function must now be prototyped for the C compiler.
I've created a standard C header and added the prototype
for MyProc. A prototype must exist for every dll export
function you wish to call.


/*  myproc.h */
        extern char *MyProc(char *pString, int pInt);
/*  end myproc.h */


The prototype is very similar to the function declaration
in myproc.c:

__declspec(dllexport)  char *MyProc (char *pString, int pInt)


You could use this to create the prototype if you wanted, just
change "__declspec(dllexport)" to "extern" and add ";"
end of statement .


Here is the test program... just a simple console app.

' MyTest.bas
  #include "myproc.h"
  Dim SendString$
  SendString$ = "Hi.. "
  SendString$ = MyProc(SendString$, 5)
  Print SendString$

  When compiling, specify the myproc import lib for the
  linker.. here is the commandline I used:

  bc mytest
  lc mytest myproc.lib
