.Net Native Interface Library

The .Net Native Interface Library (DotNetNativeInterface) is a native programming interface which provides a way for programming languages such as C, C++, Fortran, Assembly, Pascal, Java, VB, Delphi etc to interact with applications and libraries written in any of the .Net languages (such as C#, VB.Net etc). Programmers can use DotNetNativeInterface native methods to access .Net 3rd party libraries or .Net Framework Libraries without the need for registry entries, COM registrations or changes to the .Net libraries.

Free Trial

 Latest: 1.0.0.0 - What's New

runtimeLibrary4Delphi

Introduction

Programmers can produce software by combining source codes from any programming language with the .Net framework and other .Net 3rd party libraries using the DotNetNativeInterface methods. Programs written for .NET Framework execute in a software environment known as Common Language Runtime (CLR) which is an application virtual machine that provides services such as security, memory management, and exception handling.

The following examples illustrate when you need to use DotNetNativeInterface native methods:
  • You want to access and use .Net Framework Class Library in your application.
  • You want to access and use 3rd party .Net Libraries in your application.

What DotNetNativeInterface can do:

  • Load .Net assembly from file or Global Assembly Cache (GAC).
  • Create instance of .Net objects (including arrays).
  • Create and use .Net objects.
  • Invoke .Net methods (including generic methods).
  • Get or Set .Net object field and property values (including static members).
  • Subscribe and handle .Net events.
  • Catch and throw .Net exceptions.
  • Load assembly types and obtain type information.
  • ...and many more

Competitive Advantages

  • Full access to .Net Framework Class Library (Including new and emerging .NET technologies).
  • No COM registration of .Net Libraries is required when deployed.
  • Allows any programming language to consume .Net libraries as if they were native code.
  • Easy to use.

EXAMPLE

The following code loads an assembly named "mscorlib" into the current application domain and print the assembly location to the console.

C/C++
int main(int argc, char** argv) {

    ClrAssembly m_assembly = NULL;

    // Load assembly from assembly fullname
    HRESULT m_result = Assembly_Load(L"mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", m_assembly);
    if (m_result == CLR_OK) {

        // Get the assembly location
        int m_bufferLen = Assembly_GetLocation(m_assembly, NULL, 0);
        wchar_t *m_buffer = new wchar_t[m_bufferLen + 1];
        // Get the assembly location
        Assembly_GetLocation(m_assembly, m_buffer, m_bufferLen);
        std::wcout << "Assembly Location: " << m_buffer << std::endl;
        delete[] m_buffer;
    }

    return 0;
}

Object Pascal
var
  m_result: HResult;
  m_assembly: ClrAssembly;
  m_bufferLen: Integer;
  m_buffer: PWideChar;
begin
  m_assembly := nil;

  // Load assembly from assembly fullname
  m_result := Assembly_Load('mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089',
    m_assembly);
  if m_result = CLR_OK then
  begin
    // Get the assembly location
    m_bufferLen := Assembly_GetLocation(m_assembly, nil, 0);
    GetMem(m_buffer, m_bufferLen);
    try
      // get assembly location
      Assembly_GetLocation(m_assembly, m_buffer, m_bufferLen);
      Writeln('Assembly Location: '+ string(m_buffer));
    finally
      FreeMem(m_buffer);
    end;
  end;
end.

API GUIDE

The .Net Native Interface provides a rich set of functions for:
  • loading .Net assembly.
  • finding .Net type in assembly.
  • creating an instance of a .Net object.
  • getting and setting the field values of a .Net object.
  • getting and setting the property values of a .Net object.
  • invoking methods of a .Net object.
  • subscribing to and handling of a .Net object events.
  • creating an instance of a .Net array.
  • getting and setting the array elements.
  • handling .Net exceptions

Load .Net Assembly

The .Net Native Interface provides a rich set of functions for loading 3rd party .Net assemblies or .net framework library.
To load an assembly, call one of the following methods:
  • AppDomain_Load
  • Assembly_Load
  • Assembly_LoadFile
  • Assembly_LoadFrom
  • Assembly_LoadWithPartialName
  • Assembly_UnsafeLoadFrom

Find .Net Type

The .Net Native Interface provides a rich set of functions for finding .Net type in an assembly.
To find a .Net type in an assembly, call one of the following methods:
  • Assembly_FindType
  • Assembly_GetType
  • Type_GetType

Create .Net Object

The .Net Native Interface provides a rich set of functions for creating an instance of a .Net object and also for creating a static class as object.
To create an object or create a static class object, call one of the following methods:
  • NewObject
  • NewObject{num}
    • Where num represents a number from 1 to 4 which indicates the number of parameters required by the .Net object constructor.
  • NewBaseObject
  • NewObjectNoParams
  • NewStaticObject
  • NewGenericObject
  • NewObjectByType

Get/Set .Net Object Field Values

The .Net Native Interface provides a rich set of functions for getting and setting a .Net object instance or static object's field values.
To Get or Set the field values of a .Net object or a static class object, call one of the following methods:

GET Functions:

  • Object_GetFieldValueAsObject
  • Object_GetFieldValueAs{PrimitiveType}
    • PrimitiveType: Boolean, Byte, Double, Float, Int, Long, SByte, Short
  • Object_GetFieldValueAsString
  • Object_GetFieldValueAsDecimal
  • Object_GetFieldValueAsDateTime

SET Functions:

  • Object_SetFieldObjectValue
  • Object_SetField{PrimitiveType}Value
    • PrimitiveType: Boolean, Byte, Double, Float, Int, Long, SByte, Short
  • Object_SetFieldStringValue
  • Object_SetFieldDecimalValue
  • Object_SetFieldDateTimeValue

Get/Set .Net Object Property Values

The .Net Native Interface provides a rich set of functions for getting and setting a .Net object instance or static object's property values.
To Get or Set the property values of a .Net object or a static class object, call one of the following methods:

GET Functions:

  • Object_GetPropertyValueAsObject
  • Object_GetPropertyValueAs{PrimitiveType}
    • PrimitiveType: Boolean, Byte, Double, Float, Int, Long, SByte, Short
  • Object_GetPropertyValueAsString
  • Object_GetPropertyValueAsDecimal
  • Object_GetPropertyValueAsDateTime

SET Functions:

  • Object_SetPropertyObjectValue
  • Object_SetProperty{PrimitiveType}Value
    • PrimitiveType: Boolean, Byte, Double, Float, Int, Long, SByte, Short
  • Object_SetPropertyStringValue
  • Object_SetPropertyDecimalValue
  • Object_SetPropertyDateTimeValue

To Get or Set the property values of a .Net INDEXER object, call one of the following methods:

GET Indexer Functions:

  • Object_GetPropertyIndexValueAsObject
  • Object_GetPropertyIndexValueAs{PrimitiveType}
    • PrimitiveType: Boolean, Byte, Double, Float, Int, Long, SByte, Short
  • Object_GetPropertyIndexValueAsString
  • Object_GetPropertyIndexValueAsDecimal
  • Object_GetPropertyIndexValueAsDateTime

SET Indexer Functions:

  • Object_SetPropertyObjectIndexValue
  • Object_SetPropertyStringIndexValue {PrimitiveType}IndexValue
    • PrimitiveType: Boolean, Byte, Double, Float, Int, Long, SByte, Short
  • Object_SetPropertyStringIndexValue
  • Object_SetPropertyDecimalIndexValue
  • Object_SetPropertyDateTimeIndexValue

Invoke .Net Object Methods

The .Net Native Interface provides a rich set of functions for invoking a method of a .Net object instance or static object.
To invoke a non generic method of a .Net object or a static class object, call one of the following methods:
  • Object_InvokeObjectMethod
  • Object_Invoke{PrimitiveType}Method
    • PrimitiveType: Boolean, Byte, Double, Float, Int, Long, SByte, Short
  • Object_InvokeVoidMethod
  • Object_InvokeStringMethod
  • Object_InvokeDecimalMethod
  • Object_InvokeDateTimeMethod

To invoke a GENERIC method of a .Net object or a static class object, call one of the following methods:
  • Object_InvokeGenericObjectMethod
  • Object_InvokeGeneric{PrimitiveType}Method
    • PrimitiveType: Boolean, Byte, Double, Float, Int, Long, SByte, Short
  • Object_InvokeGenericVoidMethod
  • Object_InvokeGenericStringMethod
  • Object_InvokeGenericDecimalMethod
  • Object_InvokeGenericDateTimeMethod

Handle .Net Object Events

The .Net Native Interface provides a rich set of functions for subscribing to a .Net object and handling the event raised.
To subscribe to or unsubscribe from a .Net object or a static class object event, call one of the following methods:

SUBSCRIBE Functions:

  • Object_RegisterEventCallBack
  • Object_RegisterEventCallBackPointer
  • Object_RegisterEventCallBackWithReturn

UNSUBSCRIBE Functions:

  • Object_UnRegisterEventCallBack
  • Object_UnRegisterEventCallBackPointer
  • Object_UnRegisterEventCallBackWithReturn

EVENT ARGUMENTS Functions:

  • EventArgs_GetEventParameters
  • EventArgs_ToClrObject

Create .Net Array

The .Net Native Interface provides a rich set of functions for creating an instance of a .Net array object.
To create an array object, call one of the following methods:
  • Array_NewArray
  • Array_NewArrayByType
  • Array_NewAssemblyArray
  • Array_New{PrimitiveType}
    • PrimitiveType: Boolean, Byte, Double, Float, Int, Long, SByte, Short
  • Array_NewDecimalArray
  • Array_NewDateTimeArray
  • Array_NewObjectArray
  • Array_NewStringArray
  • Array_NewTypeArray

Get/Set .Net Array Elements

The .Net Native Interface provides a rich set of functions for getting and setting the element of .Net array.
To Get or Set the element of a .Net array, call one of the following methods:

GET Functions:

  • Object_GetElement
  • Object_GetElement{PrimitiveType}
    • PrimitiveType: Boolean, Byte, Double, Float, Int, Long, SByte, Short
  • Object_GetElementString
  • Object_GetElementDecimal
  • Object_GetElementDateTime

SET Functions:

  • Object_SetElement
  • Object_SetElementAs{PrimitiveType}
    • PrimitiveType: Boolean, Byte, Double, Float, Int, Long, SByte, Short
  • Object_SetElementAsString
  • Object_SetElementAsDecimal
  • Object_SetElementAsDateTime

Handle .Net Exception

The .Net Native Interface provides a rich set of functions for handling .Net exceptions.
To handle an exception, call these methods:
  • Exception_GetExceptionForErrorCode
  • Exception_Check
  • Exception_GetClrFatalError
  • Exception_Occurred
  • Exception_ToString
  • Exception_GetMessage



Compatibilities

Languages

Supported Programming Languages

The .Net Native Interface Library supports many programming languages as far as the programming language can LINK to the .Net Native Interface Library and port to the library C/C++ header files or the object pascal files.

Some of the programming languages which can use the .Net Native Interface Library to access any .Net Libraries includes:

  • C/C++
  • C++Builder
  • Java
  • Pascal
  • Delphi
  • Visual Basic
  • Python
  • ....and many more.
  • FORTRAN
  • Assembly Language
  • PHP
  • Ruby
  • JavaScript
  • Go
  • Elixir
  • MatLab
  • Perl
  • R
  • Rust
  • Typescript

Some of the programming IDE's which has been used for testing .Net Native Interface Library includes:

  • C/C++ NetBeans
  • C++Builder
  • Delphi
  • Free Pascal
  • Lazarus
  • Java

Header Files

  • C/C++
  • Object Pascal

Platforms

Supported Platforms

Platforms

  • .Net Framework 4.5.2 or higher version.
  • Any programming language Integrated Development Environment(IDE).

Windows Applications

  • Supports 32bit windows applications.

Operating Systems

  • Windows OS 32-bit.
  • Windows OS 64-bit

Download Free Trial


30-Day Fully-Functional Free Trial

Get started today and see why developers worldwide
choose CrystalNet .Net Native Interface Library.

 Download

Order Online


Starting at $149.95

.Net Native Interface Library provides a cost-effective solution for developers to to access .Net assemblies from any programming language.

 Order