convert a C++ class to a vb.NET class RRS feed

  • Question

  • i am trying to convert a c++ class to the correct vb.NET class :

    this is the c++ class :

    class ImageCodecInfo
        CLSID Clsid;
        GUID  FormatID;
        const WCHAR* CodecName;
        const WCHAR* DllName;
        const WCHAR* FormatDescription;
        const WCHAR* FilenameExtension;
        const WCHAR* MimeType;
        DWORD Flags;
        DWORD Version;
        DWORD SigCount;
        DWORD SigSize;
        const BYTE* SigPattern;
        const BYTE* SigMask;

    my convertion is :

        Public Class ImageCodecInfo

             Public Clsid As IntPtr
             Public FormatID As IntPtr

            Public DllName As IntPtr
            Public CodecName As IntPtr ' i am correct here
             Public Version As Integer
            Public FilenameExtension As IntPtr ' i am correct here
            Public MimeType As IntPtr ' i am correct here

            Public Flags As Integer 
            Public FormatDescription As IntPtr ' i am correct here
            Public SigCount As Integer
            'Public SigSize As Integer

            Public SigPattern As Byte
            Public SigMask As IntPtr
        End Class

    i need the complete informations.

    Sunday, June 17, 2018 7:12 PM

All replies

  • This class already exists in .NET : System.Drawing.Imaging.ImageCodecInfo
    • Proposed as answer by phil chelis Monday, June 18, 2018 6:11 AM
    Sunday, June 17, 2018 7:17 PM
  • i want that convertion for studying and learning.
    Sunday, June 17, 2018 7:28 PM
  • As it exists, just copy-paste it from  Namespace System.Drawing.Imaging...
    Sunday, June 17, 2018 7:43 PM
  • i want to learn how do the FieldOffset attribute works.
    Sunday, June 17, 2018 7:48 PM
  • There is no need for 'StructLayout' or 'FieldOffset' - these can be useful for strict conversions of a C 'union', but are not related to the conversion of C++ 'class' or 'struct'.

    The closest conversion I can give you for your C++ code is:

    Public Class ImageCodecInfo
    	Public Clsid As New CLSID()
    	Public FormatID As New GUID()
    	Public ReadOnly CodecName As String
    	Public ReadOnly DllName As String
    	Public ReadOnly FormatDescription As String
    	Public ReadOnly FilenameExtension As String
    	Public ReadOnly MimeType As String
    	Public Flags As UInteger
    	Public Version As UInteger
    	Public SigCount As UInteger
    	Public SigSize As UInteger
    'C++ TO VB CONVERTER TODO TASK: VB does not have an equivalent to pointers to value types:
    'ORIGINAL LINE: const Byte* SigPattern;
    	Public ReadOnly SigPattern As Byte
    'C++ TO VB CONVERTER TODO TASK: VB does not have an equivalent to pointers to value types:
    'ORIGINAL LINE: const Byte* SigMask;
    	Public ReadOnly SigMask As Byte
    End Class

    As you see the pointer to Byte is a problem.  In C++, the intent of pointers to Byte is unclear without examining the usage of these fields.  These may be arrays.

    Even the conversion of 'WCHAR*' may be unclear without examining the usage, but these usually convert to strings.  Since they're 'const' pointers, the VB equivalent are ReadOnly fields.

    C++ is the only major language where the declaration alone is often insufficient to determine the meaning - this is usually the case where pointers are involved.

    Convert between VB, C#, C++, & Java (
    Instant C# - VB to C# Converter
    Instant VB - C# to VB Converter

    Sunday, June 17, 2018 8:42 PM
  • i have encountered problem like this and i fixed it using the correct Offset of the FieldOffset attribute
    Sunday, June 17, 2018 10:16 PM
  • new updates:


    fields.                                                 its offset.


    Clsid                                                        ?

    FormatID                                                16

    CodecName                                             32

    DllName                                                  36

    FormatDescription                                   40

    FilenameExtension                                   44

    MimeType                                                48

    Version                                                    ?

    SigCount                                                 56

    SigSize                                                    60

    SigPattern                                               68

    SigMask                                                  72

    Flags                                                       52

    Monday, June 18, 2018 3:52 PM
  • But why are you trying to re-invent the wheel ?

    Copy-paste :

    Public NotInheritable Class ImageCodecInfo
       Public Property Clsid As Guid
       Public Property CodecName As String
       Public Property DllName As String
       Public Property FilenameExtension As String
       Public Property Flags As ImageCodecFlags
       Public Property FormatDescription As String
       Public Property FormatID As Guid
       Public Property MimeType As String
       Public Property SignatureMasks As Byte()()
       Public Property SignaturePatterns As Byte()()
       Public Property Version As Integer
    End Class

    Monday, June 18, 2018 4:23 PM
  • to Castorix31:

    you are write

    Monday, June 18, 2018 4:40 PM