Back to Sealevel      

Integrating SeaMAX into Your Project

Introduction

SeaMAX has been created with careful consideration of common programming languages and language interoperability. Language support is bounded by four datatypes: Integers (32 or 64-bit, system dependent), double precision floating points, byte arrays (or strings), and pointers (system dependent). If your project uses a language or compiler not listed below, yet supports these four datatypes and allows access to DLL functions, then your languages is most likely compatible with SeaMAX.

Language Support

Language support is bound by three datatypes: 4-byte integers (or longs), double precision floating points, and byte arrays (or strings). If your project uses a language or compiler not covered below, yet supports the datatypes listed previously and allows access to DLL functions, then your language should be compatible with SeaMAX.

Language and Compiler Examples

The list of languages and compilers listed below is not all-inclusive. It is a sample of the most requested languages and should not be considered complete.

DLL Errors and Exceptions

When starting a new project, you must copy all of the SeaMAX related DLLs (C:\Program Files\Sealevel Systems\SeaMAX\Dll) into your project's executable folder before executing your binary. If you are receiving 'DLL Not Found' exceptions or are receiving warnings, there is a good chance you have not copied the DLLs to the correct folder of your project. DLLs should be located in the same folder as your project's compiled executable.


 
Back to the Top

MS Visual C++ 6.0

To use SeaMAX in an existing Visual C++ 6 project initially requires three steps. First, the Vistual Studio 6.0 include and library directorys must be updated to point to the install path for SeaMAX, which (assuming a default installation) can by accomplished by the following:

  1. Choose 'Tools->Options...' from the menu bar in Visual Studio 6.0
  2. Select the 'Directories' tab and choose 'Include Files' from the 'Show Directories for' drop-down list.
  3. Add a new entry that is the directory "C:\Program Files\Sealevel Systems\SeaMAX\Include"
  4. Add a new entry to the 'Library Files' listing that is the directory "C:\Program Files\Sealevel Systems\SeaMAX\Lib"

visual_c6_1.png

Updating the Visual Studio 6 Include Path

visual_c6_2.png

Updating the Visual Studio 6 Library Path

Second, add the following include pre-processor definition to the beginning of your application source:

	#include <SeaMAX.h>
	

Finally, add the SeaMAX library file to your project by completing the following:

  1. Choose 'Project->Settings' from the menu bar.
  2. Select the 'Link' tab.
  3. At the end of the 'Object/library modules' listing, append the following text: "SeaMAX.lib"
  4. Select the 'Debug' tab.
  5. Enter 'C:\Program Files\Sealevel Systems\SeaMAX\DLL' as your working directory.
    This will allow your program to see the SeaMAX DLL at runtime.

visual_c6_3.png

Linking in the SeaMAX Library File

visual_c6_4.png

Updating the Project Working Directory

Your project should now be ready to begin using SeaMAX!


 
Back to the Top

MS Visual Basic 6.0

In Visual Basic 6.0, the SeaMAX dll can be declared function-by-function in a separate module. It is not necessary to declare all of SeaMAX in your project, only the functions you need to use.

Before inserting the DLL imports into a new module, it is best to copy the required DLLs to your project directory. The required DLLs will be located in your SeaMAX installation directory under the DLL folder. All DLLs located in this folder must be copied to your VB project folder for your executable to correctly execute.

After copying the DLLs to your project folder, create a module in your VB 6 project. Right-click on the 'modules' folder in your project tree pane. Select the 'Add->Module' option. Click the 'Open' button to insert a blank module, and paste any or all of the declarations below into the new module.

visualbasic6_1.png

Adding a New Module

Note:
Visual Basic 6.0 handles strings differently from a C-style DLL. In order to use any SeaMAX function which returns a string (such as SME_GetName() or SME_GetNetworkConfig()), the VB string passed to the DLL must already have space allocated to it - the DLL will not internally allocate memory to store it's value. An example of how to do this is below:
	Dim handle As Long

	' Any string passed to a C-type DLL must have space pre-allocated
	' which is accomplished by the * 30 or * 64, inidicating that the
	' string should have 30 or 64 characters

	Dim module As String * 30
	Dim ip As String * 64
	Dim mac As String * 64

	' Initialize SeaMAX

	handle = SME_Initialize()

	' Search for the modules and iterate through the list

	For i = 1 To SME_SearchForModules(handle)

		' Get all of the module details such as name, ip, and MAC address

		SME_GetName handle, module, 64
		SME_GetNetworkConfig handle, ip, 0, 0
		SME_GetMACAddress handle, mac
    
		' Output the strings    
		MsgBox CtoVBStr(module) & " at " & CtoVBStr(ip) & " [" & CtoVBStr(mac) & "]"
    
		SME_NextModule handle

	Next i

	' Release the memory allocated by the API

	SME_Cleanup (handle)
	

Since the strings in the above example have to be pre-allocated, VB 6 does not recognize the C-style string ending character of NULL, and therefore has problems displaying the strings properly. To correct this problem, the function CtoVBStr() has been provided below:

	Public Function CtoVBStr(ByVal cString As String) As String
		CtoVBStr = Left(cString, InStr(cString, Chr(0)) - 1)
	End Function
	


 
Back to the Top

Borland Delphi 7

The following code provides one example for importing a SeaMAX function into a Delphi 7 project. There may be other more applicable methods depending on your project. This project uses default and has a single button placed on the main form. The following code is the function created for the button's event handler:

delphi7_1.png

Creating a Default Project With Single Button

 procedure TForm1.Button1Click(Sender: TObject);
var
  handle: Thandle;
  maj: Integer;
  min: Integer;
  rev: Integer;
  bui: Integer;
  SM_GetVersion: procedure (Major:Pointer; Minor:Pointer; Revision:Pointer; Build:Pointer); stdcall;

begin
  handle := LoadLibrary('SeaMAX.dll');
  if handle >= 32 then { success }
  begin
    SM_GetVersion := GetProcAddress(handle, 'SM_Version');

    SM_GetVersion(@maj, @min, @rev, @bui);
    MessageDlg('Using SeaMAX Version ' + IntToStr(maj) + '.' + IntToStr(min) +
			   '.' + IntToStr(rev) + '.' + IntToStr(bui), mtError, [mbOk], 0)
  end
  else
    MessageDlg('Could not open the SeaMAX dll.', mtError, [mbOk], 0)
end;
 


 
Back to the Top

Microsoft .NET Languages (C#, J#, VB .NET, C++ .NET)

For 32-bit .NET applications, SeaMAX includes a CLR component which encapsulates the SeaMAX API across any .NET project.

To include the .NET component into your project, open your Microsoft Visual Studio project and select Project on the menu bar. Select the 'Add Reference...' menu item, click the Browse tab. Browse to the SeaMAX installation folder ('C:\Program Files\Sealevel Systems\SeaMAX' by default) and choose the 'SeaMAX dot Net.dll' located in the 'Dll' folder.

managed_seamax_1.png

Inserting SeaMAX as a Reference...

managed_seamax_2.png

Browsing to the SeaMAX folder

The managed SeaMAX .NET component encapsulates SeaMAX into the Sealevel namespace. The functions provided in the .NET SeaMAX class conform to the SeaMAX API documented here, with the exception that the SeaMAX handle is concealed as a private variable within the class and is automatically created and destroyed for you.

The following is an example of how to call SM_Open() within a C++ .NET project after adding the Managed SeaMAX reference:

    Sealevel.SeaMAX sm = new Sealevel.SeaMAX();

    if (sm.SM_Open("COM1") < 0)
    {
       // Error opening COM1
    };
	
 
 
Generated on 18 Sep 2007.