MDL Libraries/Functions can be wrapped

Hello,

I would like to ask what are the MDL Libraries/Functions/Classes can be wrapped using .NET. If there is, can you gave me some examples and does it have documents for it?

Best Regards,

Aldrin

Parents
  • Unknown said:
    What are the MDL Libraries/Functions/Classes...

    As I've mentioned previously in response to your questions, the MicroStation Development Library (MDL) provides a C interface.  It doesn't have any classes.

    Unknown said:
    I would like to ask what MDL Functions can be wrapped using .NET?

    The MDL help documentation includes a declaration for VBA users for each function.  For example...

    MDL Function: mdlDB_activeFormsMode

    VBA wrapper provided by MDL Function Reference:

    Declare Function mdlDB_activeFormsMode Lib "stdmdlbltin.dll" ( ByVal formsMode As Long ) As Long

    You can translate that to a .NET declaration in preparation for using P/Invoke.  You must be also aware that there are differences between VBA and .NET and that you may have to change some parameters, data types, or pass-by-reference hints.

     
    Regards, Jon Summers
    LA Solutions

  • Hello sir Jon,

    Sorry for I am a little confused on the functions can be wrapped. From the delivered reference of SDK which is MicroStation V8 MDL Function Reference, are we able to wrapped those functions we can find on that reference?

    Best Regards,

    Aldrin

  • Aldrin, each function and C structure can be represented also in C#.
    All depends on your language differences knowledge, please refer to following links:
    http://msdn.microsoft.com/en-us/library/yyaad03b%28v=vs.90%29.aspx
    http://www.binaryfortress.com/News/2010/04/converting-c-data-types-to-c/
    http://www.albahari.com/valuevsreftypes.aspx

    Then, if you will know the differences, you can use P/Invoke to import any MDL function.

    You can start here: http://msdn.microsoft.com/en-us/library/aa446536.aspx


    C# from version 2.0 also supports _cdecl calling convention, that makes wrapping even better.

    You can find handy also a tool P/Invoke Interop Assistant:
    http://blogs.msdn.com/b/vbteam/archive/2008/03/14/making-pinvoke-easy.aspx

    If you would need a C# declaration of any MDL function, make a post and somebody helps you,
    but I thing that after a fair amount of wrapped functions you will be able to do it alone.

    Example:
    MDL function looks like:
    BoolInt mdlElmdscr_areIdenticalToTolerance  
    (
    MSElementDescr*       edP1 ,
    MSElementDescr*       edP2 ,
    UInt32       comparisonFlags ,
    double       distanceTolerance ,
    double       directionTolerance  
    );

    VBA declaration looks like:
    Declare Function mdlElmdscr_areIdenticalToTolerance Lib "stdmdlbltin.dll" ( _
      ByVal edP1 As Long , _
      ByVal edP2 As Long , _
      ByVal comparisonFlags As Long , _
      ByVal distanceTolerance As Double , _
      ByVal directionTolerance As Double _
    ) As Long

    So, as you can see, return value type BoolInt is mapped to VB Long, this is because both types
    are 4 bytes, that means, we will need a 4 bytes integer in C#, so we can use Int32 or its typedef int,
    or we can use C# enum

    enum BoolInt : int
    {
      FALSE = 0,
      TRUE = 1
    }

    Also edP1 and edP2 are mapped to VB Long, this is bacasue pointers are in 32 bit applications 4 bytes long
    as well and VBA as is does not support pointers. However C# does support pointers, so it depends on what you
    are going to do. If you are going to use this function with COM interop, then it is better to
    keep declaration VBA compatible, so to use Int32 also here.
    Arguments distanceTolerance and directionTolerance are mapped to double, because both C and VB uses
    equal datatype double, which is 8 bytes long.  
    Argument comparisonFlags is of type UInt32, which is a typedef of unsigned int, so in C# we can use
    uint, which is UInt32 type, or make an enum from defines located in mselmdsc.fdf

    defines look like:
    #define COMPAREOPT_IGNORE_MODEL_DIFFS                       (1<<0)
    #define COMPAREOPT_IGNORE_SYMBOLOGY                         (1<<1)
    #define COMPAREOPT_IGNORE_IDS                               (1<<2)
    #define COMPAREOPT_IGNORE_LINKAGES                          (1<<3)
    #define COMPAREOPT_IGNORE_MODIFIED                          (1<<4)
    #define COMPAREOPT_IGNORE_DGNSTORE                          (1<<5)
    #define COMPAREOPT_IGNORE_ATTRIBUTE_VALUE                   (1<<6)
    #define COMPAREOPT_IGNORE_SINGLE_EDF_VALUES                 (1<<7)
    #define COMPAREOPT_IGNORE_CELL_RANGEDIAG                    (1<<8)
    Note: there are more, but this is only example...

    we can translate this to C# enum:

    [Flags]
    enum COMPAREOPT : uint
    {
      IGNORE_MODEL_DIFFS          = 1<<0,
      IGNORE_SYMBOLOGY            = 1<<1,
      IGNORE_IDS                  = 1<<2,
      IGNORE_LINKAGES             = 1<<3,
      IGNORE_MODIFIED             = 1<<4,
      IGNORE_DGNSTORE             = 1<<5,
      IGNORE_ATTRIBUTE_VALUE      = 1<<6,
      IGNORE_SINGLE_EDF_VALUES    = 1<<7,
      IGNORE_CELL_RANGEDIAG       = 1<<8
      Note: there are more, but this is only example..
    }

    then C# declaration without use of enums could look as follows:
    [DllImport("stdmdlbltin.dll", CallingConvention=CallingConvention.StdCall)]
    public static extern int mdlElmdscr_areIdenticalToTolerance
    (
    int edP1 ,
    int edP2 ,
    uint comparisonFlags ,
    double distanceTolerance ,
    double directionTolerance  
    );

    Or with use of enums:
    [DllImport("stdmdlbltin.dll", CallingConvention=CallingConvention.StdCall)]
    public static extern BoolInt mdlElmdscr_areIdenticalToTolerance
    (
    int edP1 ,
    int edP2 ,
    COMPAREOPT comparisonFlags ,
    double distanceTolerance ,
    double directionTolerance  
    );

    Or to use original MDL function from ustation.dll in _cdecl convention:
    Note: with use of enums and IntPtr for pointers
    [DllImport("ustation.dll", CallingConvention=CallingConvention.Cdecl)]
    public static extern BoolInt mdlElmdscr_areIdenticalToTolerance
    (
    IntPtr edP1 ,
    IntPtr edP2 ,
    COMPAREOPT comparisonFlags ,
    double distanceTolerance ,
    double directionTolerance  
    );




Reply
  • Aldrin, each function and C structure can be represented also in C#.
    All depends on your language differences knowledge, please refer to following links:
    http://msdn.microsoft.com/en-us/library/yyaad03b%28v=vs.90%29.aspx
    http://www.binaryfortress.com/News/2010/04/converting-c-data-types-to-c/
    http://www.albahari.com/valuevsreftypes.aspx

    Then, if you will know the differences, you can use P/Invoke to import any MDL function.

    You can start here: http://msdn.microsoft.com/en-us/library/aa446536.aspx


    C# from version 2.0 also supports _cdecl calling convention, that makes wrapping even better.

    You can find handy also a tool P/Invoke Interop Assistant:
    http://blogs.msdn.com/b/vbteam/archive/2008/03/14/making-pinvoke-easy.aspx

    If you would need a C# declaration of any MDL function, make a post and somebody helps you,
    but I thing that after a fair amount of wrapped functions you will be able to do it alone.

    Example:
    MDL function looks like:
    BoolInt mdlElmdscr_areIdenticalToTolerance  
    (
    MSElementDescr*       edP1 ,
    MSElementDescr*       edP2 ,
    UInt32       comparisonFlags ,
    double       distanceTolerance ,
    double       directionTolerance  
    );

    VBA declaration looks like:
    Declare Function mdlElmdscr_areIdenticalToTolerance Lib "stdmdlbltin.dll" ( _
      ByVal edP1 As Long , _
      ByVal edP2 As Long , _
      ByVal comparisonFlags As Long , _
      ByVal distanceTolerance As Double , _
      ByVal directionTolerance As Double _
    ) As Long

    So, as you can see, return value type BoolInt is mapped to VB Long, this is because both types
    are 4 bytes, that means, we will need a 4 bytes integer in C#, so we can use Int32 or its typedef int,
    or we can use C# enum

    enum BoolInt : int
    {
      FALSE = 0,
      TRUE = 1
    }

    Also edP1 and edP2 are mapped to VB Long, this is bacasue pointers are in 32 bit applications 4 bytes long
    as well and VBA as is does not support pointers. However C# does support pointers, so it depends on what you
    are going to do. If you are going to use this function with COM interop, then it is better to
    keep declaration VBA compatible, so to use Int32 also here.
    Arguments distanceTolerance and directionTolerance are mapped to double, because both C and VB uses
    equal datatype double, which is 8 bytes long.  
    Argument comparisonFlags is of type UInt32, which is a typedef of unsigned int, so in C# we can use
    uint, which is UInt32 type, or make an enum from defines located in mselmdsc.fdf

    defines look like:
    #define COMPAREOPT_IGNORE_MODEL_DIFFS                       (1<<0)
    #define COMPAREOPT_IGNORE_SYMBOLOGY                         (1<<1)
    #define COMPAREOPT_IGNORE_IDS                               (1<<2)
    #define COMPAREOPT_IGNORE_LINKAGES                          (1<<3)
    #define COMPAREOPT_IGNORE_MODIFIED                          (1<<4)
    #define COMPAREOPT_IGNORE_DGNSTORE                          (1<<5)
    #define COMPAREOPT_IGNORE_ATTRIBUTE_VALUE                   (1<<6)
    #define COMPAREOPT_IGNORE_SINGLE_EDF_VALUES                 (1<<7)
    #define COMPAREOPT_IGNORE_CELL_RANGEDIAG                    (1<<8)
    Note: there are more, but this is only example...

    we can translate this to C# enum:

    [Flags]
    enum COMPAREOPT : uint
    {
      IGNORE_MODEL_DIFFS          = 1<<0,
      IGNORE_SYMBOLOGY            = 1<<1,
      IGNORE_IDS                  = 1<<2,
      IGNORE_LINKAGES             = 1<<3,
      IGNORE_MODIFIED             = 1<<4,
      IGNORE_DGNSTORE             = 1<<5,
      IGNORE_ATTRIBUTE_VALUE      = 1<<6,
      IGNORE_SINGLE_EDF_VALUES    = 1<<7,
      IGNORE_CELL_RANGEDIAG       = 1<<8
      Note: there are more, but this is only example..
    }

    then C# declaration without use of enums could look as follows:
    [DllImport("stdmdlbltin.dll", CallingConvention=CallingConvention.StdCall)]
    public static extern int mdlElmdscr_areIdenticalToTolerance
    (
    int edP1 ,
    int edP2 ,
    uint comparisonFlags ,
    double distanceTolerance ,
    double directionTolerance  
    );

    Or with use of enums:
    [DllImport("stdmdlbltin.dll", CallingConvention=CallingConvention.StdCall)]
    public static extern BoolInt mdlElmdscr_areIdenticalToTolerance
    (
    int edP1 ,
    int edP2 ,
    COMPAREOPT comparisonFlags ,
    double distanceTolerance ,
    double directionTolerance  
    );

    Or to use original MDL function from ustation.dll in _cdecl convention:
    Note: with use of enums and IntPtr for pointers
    [DllImport("ustation.dll", CallingConvention=CallingConvention.Cdecl)]
    public static extern BoolInt mdlElmdscr_areIdenticalToTolerance
    (
    IntPtr edP1 ,
    IntPtr edP2 ,
    COMPAREOPT comparisonFlags ,
    double distanceTolerance ,
    double directionTolerance  
    );




Children
No Data