#4 MPEG4TagSupport.dll C# Support

closed
nobody
other (2)
5
2006-11-26
2006-11-26
Justin J. Novack
No

I would love to see C# support for the MPEG4TagSupport DLL. Current I'm using AtomicParsley for the reading and writing, but that's so kludgy.

Discussion

  • M@B
    M@B
    2006-11-26

    Logged In: YES
    user_id=1364593
    Originator: NO

    What do you mean by "C#" support ?

    MPEG4TagSupport.dll is a completely standard Win32 C DLL...You could add it as a dependency for an unmanaged project with no problem...You just have to force the export of the function.

    Would you want it to be embedded in a managed object to be able to access it through your pure C# code...It is also possible...

    Excerpt from a 15second.com article :
    "Using Win32 DLL Functions from Managed Applications

    Calling Win32 DLL functions from managed code is possible. .NET Platform Invocation Service (PInvoke) is used for this task. There is a namespace named System.Runtime.InteropServices that allows us to access the PInvoke service.

    For demonstration purposes I have created a simple client application named ManagedClient2.exe.

    That application displays the name of the computer. It uses a Win32 application programming interface (API) function named GetComputerName to obtain the name of the computer.

    The code is shown below:

    1 using System;
    2 using System.Text ;
    3 using System.Runtime.InteropServices;
    4
    5 class ManagedClient2
    6 {
    7 [DllImport("kernel32.dll")]
    8 public static extern bool GetComputerNameA(
    9 [MarshalAs(UnmanagedType.LPStr)] StringBuilder
    r_strComputerName,
    10 ref int r_iLength) ;
    11 public static int Main()
    12 {
    13 int iLength = 255 ;
    14 bool bReturnValue = false ;
    15 StringBuilder strComputerName = new
    StringBuilder(iLength) ;
    16 bReturnValue = GetComputerNameA(strComputerName, ref
    iLength) ;
    17 Console.WriteLine("Your computer name is " +
    strComputerName) ;
    18 Console.WriteLine("\nPress any key to exit") ;
    19 Console.Read() ;
    20 return 0 ;
    21 }
    22 }

    Use the following command in the DOS box or use BuildManagedClient2.bat file for compiling the ManagedClient2.cs file.

    csc /out:ManagedClient2.exe ManagedClient2.cs
    pause

    Running this command will create the ManagedClient2.exe file and running that file would produce the following output (Your machine name will be displayed in your output):

    To use DLL exported functions from the managed environment one must declare DLL functions, just like I did on Lines 7, 8, 9, and 10. I have broken the declaration to multiple lines just for readability purposes, but they can be merged into a single line.

    The DlImport attribute is used to specify the location of the DLL that contains the implementation of the external method. Similarly, the static and external keywords are used to tell the compiler that this method is not in the current module, rather it is in some external module.

    Note that I have used some special attribute with method parameters. These instructions are for the .NET marshaller so that it could convert .NET types to the types expected by the DLL function and vice versa. For example, the [MarshalAs(UnmanagedType.LPStr)] attribute tells the marshaller to convert the parameter to a pointer to ANSI string and pass that pointer to the DLL function. You must use correct attributes depending on the types expected by the DLL functions, otherwise runtime exceptions might occur. In the same way, the ref attribute with r_Ilength parameter tells the marshaller to pass a pointer to the passed parameter to DLL function. After declaring the functions that you want to call, you are all set. Go and call those functions as if they belong to the current module. "

    Enjoy it at : http://www.15seconds.com/issue/010129.htm

    If you have more precise need, or want to add your C# wrapper project to the WMPTagSupportExtender software galaxy...

    You know where to find me :)

    MaB_fr

     
  • M@B
    M@B
    2006-11-26

    • status: open --> closed