![]() | ![]() |
|
![]() | ||
Integrating SeaMAX into Your ProjectIntroductionSeaMAX 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 SupportLanguage 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 ExamplesThe 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 ExceptionsWhen 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.
MS Visual C++ 6.0To 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:
Updating the Visual Studio 6 Include Path
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:
Linking in the SeaMAX Library File
Updating the Project Working Directory Your project should now be ready to begin using SeaMAX!
MS Visual Basic 6.0In 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.
Adding a New Module
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
Borland Delphi 7The 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:
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;
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.
Inserting SeaMAX as a Reference...
Browsing to the SeaMAX folder 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. |