Log in

View Full Version : .NET P/Invoke to get codec data


stax76
10th October 2003, 15:37
some codecs don't save there settings in the registry like Rududu, Microsoft etc. so it can't be supported in DVX or GK whitout doing P/Invoke or knowing the codec data structure. Working with the codec data structure is not a option because the structure might change and I don't want to reverse engineer it all the time so I have to do P/Invoke and give up the possibility to configure things like the bitrate automatically. I was reading the .NET interop docs and found some things how to get a object of the codec data but don't know what .NET type I have to cast it and how I get a base64 string then. Any ideas?

jonny
10th October 2003, 16:03
I dunno what is exactly a "P/Invoke".

If i understand what you need, in C is something like this:

ICOpen
ICConfigure
ICGetStateSize
ICGetState

With ICGetState you get raw data, ready to be converted in base64 and passed to VDub.
(for base64 it's better to get/study the specs, anyway is something similar to express data in a different base, like binary or hex).

stax76
11th October 2003, 23:32
I know the API's but the problem is to marshall it to .NET, maybe someone at usenet knows, this is what I've tried:


Imports System.Runtime.InteropServices

Public Class Codec
Private Declare Function ICClose Lib "msvfw32.dll" (ByVal hic As Integer) As Integer
Private Declare Function ICOpen Lib "msvfw32.dll" (ByVal fccType As Integer, ByVal fccHandler As Integer, ByVal wMode As Integer) As Integer
Private Declare Function ICSendMessage Lib "msvfw32.dll" (ByVal hic As Integer, ByVal msg As Integer, ByVal dw1 As Integer, ByVal dw2 As Integer) As Integer
Private Declare Function ICSendMessage Lib "msvfw32.dll" (ByVal hic As Integer, ByVal msg As Integer, ByRef dw1 As IntPtr, ByRef dw2 As Integer) As Integer
Private Declare Function mmioStringToFOURCC Lib "winmm.dll" Alias "mmioStringToFOURCCA" (ByVal sz As String, ByVal uFlags As Integer) As Integer

Public Shared Function GetCodecConfigurationAsBase64String() As String
Const ICM_GETSTATE As Integer = 20480
Const ICM_SETSTATE As Integer = 20481
Const MMIO_TOUPPER As Integer = 16
Const ICMODE_QUERY As Integer = 4
Dim fccType, fccHandler, hic As Integer
fccType = mmioStringToFOURCC("vidc", MMIO_TOUPPER)
fccHandler = mmioStringToFOURCC("iv50", MMIO_TOUPPER)
'get handle of the codec
hic = ICOpen(fccType, fccHandler, ICMODE_QUERY)
'get size of the memory block
Dim size As Integer = ICSendMessage(hic, ICM_GETSTATE, 0, 0)
'allocate the memory block
Dim memoryBlock As IntPtr = Marshal.AllocHGlobal(size)
'get the codec data
ICSendMessage(hic, ICM_GETSTATE, memoryBlock, 0)
ICClose(hic)
Dim byteArray(size - 1) As Byte
'marshal memory block to byte array
'I'm getting a error here the structure
'does not have layout information
Marshal.PtrToStructure(memoryBlock, byteArray)
Marshal.FreeHGlobal(memoryBlock)
Return Convert.ToBase64String(byteArray)
End Function
End Class

stax76
12th October 2003, 01:24
I figured it out with help by usenet. I didn't notice
the Marshal.Copy method has overloads to copy from
pointer to array, I thought all overloads copy the
other way around from array to pointer so I thought
I must use Marshal.PtrToStructure which failed