MapBasic Support DLL's for Codewright

Overview
The MBSupp32 and CBExtn32 dlls provide a number of functions useful to the MapBasic programmer.  These include:
1. Move to next error in a .mb source file after compiling
2. Run the MapBasic program that is currently being edited (after compiling, of course)
* If MapInfo is running, start the mbx via DDE
* Otherwise, start MapInfo with the .mbx on the command line
3. Specify the path and filename of the MapInfo to run
4. "Routines" function - list all the Subs and Functions, in the current file, in a list box.  The list can be sorted, or displayed as found in the source file.  Jump straight to a Sub or Function by double-clicking the name.
5. Smart indenting for most MapBasic keywords.
6. "ChromaCoding" and template expansion for MapBasic keywords.
7. A comment function to place comment characters around a marked block of text.

Note: These dlls are built for, and tested with, the 32-bit version of Codewright, v. 4.0.  These will not work with 16-bit Codewright.


Installation and Use
1.	Decompress the Archives.  
	To expand the archive that you downloaded, simply run the EXE program from the DOS prompt, File Manager, or Explorer.  After you run the self extracting archive you will have 9 files in your temporary directory. 

2.  Copy  files into Codewright Directory
	Copy all 9 files into the directory where Codewright is installed.


3. 	Load the DLL(s).To use the dll's, load them through Codewright's
    Tools|Libraries dialog by clicking on the "Add" button and 
    browsing for the appropriate DLLs.
	The preceding process adds the following lines to Codewright's 
	configuration file (Cwright.ini) located in the Codewright directory.  
		
		LibPreLoad=<path>CBExtn32.dll
		LibPreLoad=<path>MBSupp32.dll

    (When using 16 bit Codewright only MBSupp.dll needs to be loaded.)

4.	Add the following lines to Cwright.ini (close Codewright 
    when editing cwright.ini)  under the [Editor] section:
		
		ExtReadKeywordFile=".mb", "<path>\mbkey.txt"
		ExtReadTemplateFile=".mb", "<path>\mbtplat.txt"

	The keyword file mbkey.txt contains the MapBasic keywords which will be used by the ChromaCoding feature.  The template file mbtplat.txt contains the MapBasic languauge templates used by the template expansion feature.  See Xcmds.doc for more information on the templates in mbtplat.txt.


5. 	Save the Cwright.ini
	Select FILE > SAVE and overwrite the existing file.

6. 	Open Codewright editor
	By double clicking on the Codewright icon.

7.	Add MapBasic file types to Codewright, and enable smart indenting,
	template expansion, and ChromaCoding. Select the DOCUMENT > LANGUAGE
	menu option and go to the EDIT tab.  Click on the NEW TYPE... button.
	Type .mb and click OK.  While still in the EDIT tab:
	* To turn on smartindenting, check the Smart Indenting  box in the Enhanced 
	  Editing group.
	* To turn on template expansion, check the Template expansion box in the
	  Enhanced Editing group. * To turn on ChromaCoding, check the Language
	  dependent box in the ChromaCoding group. Click on OK.


8.  To set up compiling from within Codewright
	Go to the DOCUMENT > LANGUAGE >COMPILER tab.  Click NEW  > type MapBasic Compile.  
	Click into the Compile box and type:  <path> \mapbasic.exe -d "%b%e"

	Note:  The "-d "; this tells MapBasic to compile and exit.  The quotes around the "%b%e" macro allow the use of long filenames.
	
	You can set up a command for a .mbp file, as well.
	For linking a MapBasic project (.mbp file):  
		<path>\mapbasic.exe -l %b%e


9. 	Set Compile Setting
	Since the error output setting is maintained on a per-project basis, you may need to set up a Codewright project that you'll do MapBasic development in.  Assuming that, here's the PROJECT > PROPERTIES > TOOLS tab:

	"No Command Shell" is checked, since MapBasic is a Windows app.  
	"Redirect Output" is unchecked, since MapBasic sends error information to a file automatically.


10. 	Set the Error File
	You need to set the error file to MapBasics.  Select  PROJECT > PROPERITIES > click the ERRORS tab

	The error file name is the path and name of the file being compiled, with a ".err" extension.   Make sure the _MapBasicErrInfo is one of the error parsers listed.

	After compiling a .mb file (or linking a .mbp file), Codewright will look for and parse the error file.  (You may have to use Search >Find Next Error.)

11. 	Add MapBasic Help File
	Select the HELP > CONFIGURE INDEX FILE... menu option.  Click ADD... and find the MapBasic help file.  Add the MapBasic help file directory to the Search Path at the bottom of the dialog.  Click  SAVE.





Function Descriptions
The functions exported to Codewright are listed below.

RunMB()
The RunMB function tries to send a DDE message to MapInfo to run the .mb or .mbp file currently being edited.  If the DDE message fails, RunMB tries to start MapInfo with the mbx on the command line.

If SetMIname has not been used to specify the path and name of MapInfo, RunMB looks for MapInfo in the following places:
* check cwright.ini for section [MBSupport], entry MIExe (this must contain the exe name, and, optionally, a path).
* check win.ini for MapInfoDir in the [MapInfo] section;
* offer to use C:\MAPINFOW\MAPINFOW.EXE (a built in default), or cancel.


You can specify the copy of MapInfo to use by adding a section to cwright.ini, like this:
[MBSupport]
MIExe="d:\mapinfo\mapinfow.exe"  
SetMIname(LPSTR szName)
SetMIname("d:\path\miname") will tell the dll where to find MapInfo. This can be handy if you are testing with different versions of MapInfo (the full product and a runtime, for example).
_MapBasicErrInfo()
This is used by Codewright, and will never be called by the user.
_mb_routines
This is used by Codewright, and will never be called by the user.

SortRoutines(BOOL bSort)
Controls whether the Sub and Function names are sorted in the dialog.  Default is TRUE.  This can be used on the Codewright command line (e. g., "SortRoutines 1"), or in the cwright.ini file (e. g., "SortRoutines=1").
cmnt()
Place comment characters around a selected block.
Two styles of comments are available:
    '*
    ' Single column; single or 
    ' multi-line 
    '*
    and

    '*----------------------------------------------------------*
    ' Multi-column boxed, single or multi line
    '
    '*----------------------------------------------------------*
Use a 'block' mark in the first column for a single column, or widen the block mark to the width of the desired block.
Sorry, the comment characters and styles are hard-coded for now; someday they will come out of the .ini file.  (However, Codewright has a similar function built in, and allows you to choose the comment and border characters.)

Use the Tools->Keyboard dialog to bind a key to the cmnt() function, or add a line like:
KmapAssign='<Ctrl-K>' 'cmnt'
to cwright.ini.

(The cmnt function recognizes .c, .cpp, .h, .mb, .asm, .bas, .mak, and .bat extensions, and provides appropriate comment characters.)



More information
Please send questions, problems, and suggestions to:
Test Drive Center
MapInfo Corp.
Two Global View 
Troy, NY 12180-8399

Internet: Testdrive.bates@mapinfo.com



6



