Author Topic: 22. Creating the Static Lib File  (Read 962 times)

0 Members and 1 Guest are viewing this topic.

Offline LarryMc

  • Administrator
  • Hero Member
  • *****
  • Posts: 5965
  • 'All I like is finishing'
22. Creating the Static Lib File
« on: September 20, 2011, 05:04:01 AM »
We now have code at a point where we can create our static library that we will share with others.  This step in the process is the simplest thing of all we have done or will do in this entire effort.

We start by creating a new project.  On the IWBasic IDE main menu click File, New, Project. This will open the New Project dialog.
For our project name we'll use 'CCT_Library.iwp'.  It could be anything, the name here is not really important.
For project type we select 'Static Library'.
For Output File we'll enter 'myControl.lib'.  This entry is important.  We picked this named because of what we entered in Section 1 of CCT_test.iwb at line # 17:

Code: [Select]
'$USE "myControl.lib" /* uncomment when converted to include file */
The two HAVE to match.

Click OK to create the project.

Open the CCT_lib.iwb file that we created our control in.  Right click anywhere on it and select the Insert File into Project option. The file is now part of the project.  From the IDE main menu select File, Save Project.  From the IDE main toolbar click the Rebuild Project button.  It is the one with 'EXE' written on it with two down arrows.  The lib file is now created.

Close the project in the IDE.

Open Windows Explorer and copy the 'myControl.lib' file from its current folder to the IWBDev \ libs folder.

That's all we have to do with the library file.  Now we'll turn our attention to the CCT_test.iwb file.

We don't want to modify this file directly since we may want to do some more development work in the future to add more features.  So the first thing we will do is make a copy of the file.  We'll rename the copy to 'CCT_Demo.iwb'.

Open the 'CCT_Demo.iwb' file in the IDE.

From the IDE main menu select File, New, Source File. Now select File, Save As.  In the dialog that appears enter 'myControl' and in the Save As Type combo select IWBASIC Include Files(*inc) option. Click Save.

Returning to  'CCT_Demo.iwb' we need to cut (not delete) the actual code in Section 1 and paste that code into 'myControl.inc'.  This results in the include file looking like this:

Code: [Select]
$USE "myControl.lib" /* uncomment when converted to include file */
DECLARE EXTERN CreateGageRLM(win as WINDOW,l as INT,t as INT,d as INT,id as UINT )
DECLARE EXTERN ConfigGageRLM(win as WINDOW,style as int,title as string,u as string,rawmin as int,rawmax as int,dialmin as int,dialmax as int,sf as int,id as UINT )
DECLARE EXTERN SetGagePanelColorRLM(win as WINDOW,id as UINT,pnlcolor as UINT)
DECLARE EXTERN SetGageDialDarkRLM(win as WINDOW,id as UINT,state as INT)
DECLARE EXTERN SetGagePos1RLM(win as WINDOW,id as UINT,pos as INT)
DECLARE EXTERN SetGagePos2RLM(win as WINDOW,id as UINT,pos as INT)

const ROUND270B = 1
const ROUND270T = 2
const ROUND270L = 3
const ROUND270R = 4
const ROUND360SGL = 5
const ROUND360DBL = 6
const ROUNDCLOCK12 = 7
const ROUNDCLOCK24 = 8
const ROUND2PENV = 9
const ROUND2PENH = 10

const GNMLDOWN = 0x501
const GNMLUP = 0x502
const GNMRDOWN = 0x503
const GNMRUP = 0x504

There is one additional entry that needs to be made:

Code: [Select]
$USE "gdiplus.lib"
We'll make it the second line in the file.

If you remember, GDI+ is a windows DLL file.  In order for us to use it we had to create a "linking' lib file.  The 'linking' lib file contained the name and location of the DLL along with the name and location of each function.  When you compile a program with a 'linking' lib the actual code is not placed in the user's exe file.  The name and locations of functions used are inserted in the appropriate places.  At run time the DLL is loaded into memory and the appropriate function is executed.  So, in order, to compile our demo with our STATIC library that uses a 'linking' lib we need to tell it use use our 'linking' lib even though our demo program doesn't call any GDI+ functions directly.  Had the GDI+ functions been supplied as a static library all the actual function code for the functions we used in our library would be in our library and there would be no need to add this additional $USE entry here.

Save the  'myControl.inc'. Save a copy of it to the IWBDev\include folder. We are now through with it.

Returning again to  'CCT_Demo.iwb' we have the following in Section 1:

Code: [Select]
/*----------------SECTION 1----------------------------------
 This section contains declarations that will be converted into an include file that
 User's will use in there applications with the following line:
$INCLUDE "myControl.inc"
------------------------------------------------------------*/

/*=============== END OF SECTION 1 =========================*/

We change it to look like this:

Code: [Select]
/*----------------SECTION 1----------------------------------
 This section contains declarations that will be converted into an include file that
 User's will use in there applications with the following line:
'$INCLUDE "myControl.inc"
------------------------------------------------------------*/
$INCLUDE "myControl.inc"
/*=============== END OF SECTION 1 =========================*/

That is the last of the changes for this file.  However, if this to be a true demo all the section comments need to be removed.  We'll leave that to the reader.

The last thing we need to do to this file is to compile it as a Windows executable.

We now have a distributable static lib, its associated include file and a demo program.

_______________________________________________

Coming Next - Sharing Our Library
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library