I am having a similar problem
In some weird cases the dll tool fails to build
For Example this function in C# will cause the dll tool
to show the error:
private static Array samples;
private const int SAMPLES = 8;
public static int tickme()
{
samples = buffer.Read(0, typeof(Int16), LockFlag.FromWriteCursor, SAMPLE_FORMAT_ARRAY);
int average = 0;
for (int i = 0; i < SAMPLES; i++)
{
average += (Int16)samples.GetValue(i, 0, 0);
}
double am = Math.Max((average / SAMPLES) / 10, 0);
return (int)am;
}
string table:
TICKME[%L0%tickme%
and somehow if I comment these lines it works!!
samples = buffer.Read(0, typeof(Int16), LockFlag.FromWriteCursor, SAMPLE_FORMAT_ARRAY);
average += (Int16)samples.GetValue(i, 0, 0);
ILcode:
.assembly extern mscorlib
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 2:0:0:0
}
.assembly extern Microsoft.DirectX.DirectSound
{
.publickeytoken = (31 BF 38 56 AD 36 4E 35 ) // 1.8V.6N5
.ver 1:0:2902:0
}
.assembly extern mscorlib as mscorlib_2
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.hash = (AB 74 A6 A8 1D E6 70 59 FD BE DE D7 9F 2F E3 E4 // .t....pY...../..
7B 27 2C 18 ) // {',.
.ver 1:0:5000:0
}
.assembly SoundDetectorLast
{
.custom instance void [mscorlib]System.Reflection.AssemblyCopyrightAttribute::.ctor(string) = ( 01 00 1A 43 6F 70 79 72 69 67 68 74 20 C2 A9 20 // ...Copyright ..
32 44 69 67 69 74 61 6C 20 32 30 30 38 00 00 ) // 2Digital 2008..
.custom instance void [mscorlib]System.Reflection.AssemblyTitleAttribute::.ctor(string) = ( 01 00 11 53 6F 75 6E 64 44 65 74 65 63 74 6F 72 // ...SoundDetector
4C 61 73 74 00 00 ) // Last..
.custom instance void [mscorlib]System.Reflection.AssemblyDescriptionAttribute::.ctor(string) = ( 01 00 00 00 00 )
.custom instance void [mscorlib]System.Reflection.AssemblyConfigurationAttribute::.ctor(string) = ( 01 00 00 00 00 )
.custom instance void [mscorlib]System.Reflection.AssemblyCompanyAttribute::.ctor(string) = ( 01 00 08 32 44 69 67 69 74 61 6C 00 00 ) // ...2Digital..
.custom instance void [mscorlib]System.Reflection.AssemblyProductAttribute::.ctor(string) = ( 01 00 11 53 6F 75 6E 64 44 65 74 65 63 74 6F 72 // ...SoundDetector
4C 61 73 74 00 00 ) // Last..
.custom instance void [mscorlib]System.Runtime.InteropServices.GuidAttribute::.ctor(string) = ( 01 00 24 63 36 64 63 64 37 64 31 2D 36 33 64 31 // ..$c6dcd7d1-63d1
2D 34 33 38 62 2D 39 32 66 65 2D 35 33 64 39 33 // -438b-92fe-53d93
64 63 37 32 36 36 38 00 00 ) // dc72668..
.custom instance void [mscorlib]System.Reflection.AssemblyTrademarkAttribute::.ctor(string) = ( 01 00 00 00 00 )
.custom instance void [mscorlib]System.Runtime.InteropServices.ComVisibleAttribute::.ctor(bool) = ( 01 00 00 00 00 )
.custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx
63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows.
.custom instance void [mscorlib]System.Reflection.AssemblyFileVersionAttribute::.ctor(string) = ( 01 00 07 31 2E 30 2E 30 2E 30 00 00 ) // ...1.0.0.0..
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 )
.hash algorithm 0x00008004
.ver 1:0:0:0
}
.module SoundDetectorLast.dll
.imagebase 0x00400000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY
.class public auto ansi beforefieldinit SoundDetectorLast.Class1
extends [mscorlib]System.Object
{
.field private static literal int32 SAMPLES = int32(0x00000008)
.field private static int32[] SAMPLE_FORMAT_ARRAY
.field private static class [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.CaptureDevicesCollection audioDevices
.field private static class [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.CaptureBuffer buffer
.field private static class [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.DevicesCollection dc
.field private static class [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.Capture cap
.field private static valuetype [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.CaptureBufferDescription desc
.field private static valuetype [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.WaveFormat wf
.field private static class [mscorlib]System.Array samples
.method public hidebysig static void modopt([mscorlib]System.Runtime.InteropServices.CallConvCdecl) initSound() cil managed
{
.vtentry 1 : 1
.export [1] as initSound
.maxstack 3
.locals init ([0] valuetype [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.DeviceInformation CS$0$0000)
IL_0000: newobj instance void [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.DevicesCollection::.ctor()
IL_0005: stsfld class [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.DevicesCollection SoundDetectorLast.Class1::dc
IL_000a: newobj instance void [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.CaptureDevicesCollection::.ctor()
IL_000f: stsfld class [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.CaptureDevicesCollection SoundDetectorLast.Class1::audioDevices
IL_0014: ldsfld class [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.CaptureDevicesCollection SoundDetectorLast.Class1::audioDevices
IL_0019: ldc.i4.0
IL_001a: callvirt instance valuetype [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.DeviceInformation [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.CaptureDevicesCollection::get_Item(int32)
IL_001f: stloc.0
IL_0020: ldloca.s CS$0$0000
IL_0022: call instance valuetype [mscorlib_2]System.Guid [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.DeviceInformation::get_DriverGuid()
IL_0027: newobj instance void [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.Capture::.ctor(valuetype [mscorlib_2]System.Guid)
IL_002c: stsfld class [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.Capture SoundDetectorLast.Class1::cap
IL_0031: newobj instance void [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.CaptureBufferDescription::.ctor()
IL_0036: stsfld valuetype [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.CaptureBufferDescription SoundDetectorLast.Class1::desc
IL_003b: newobj instance void [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.WaveFormat::.ctor()
IL_0040: stsfld valuetype [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.WaveFormat SoundDetectorLast.Class1::wf
IL_0045: ldsflda valuetype [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.WaveFormat SoundDetectorLast.Class1::wf
IL_004a: ldc.i4.s 16
IL_004c: call instance void [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.WaveFormat::set_BitsPerSample(int16)
IL_0051: ldsflda valuetype [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.WaveFormat SoundDetectorLast.Class1::wf
IL_0056: ldc.i4 0xac44
IL_005b: call instance void [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.WaveFormat::set_SamplesPerSecond(int32)
IL_0060: ldsflda valuetype [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.WaveFormat SoundDetectorLast.Class1::wf
IL_0065: ldc.i4.2
IL_0066: call instance void [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.WaveFormat::set_Channels(int16)
IL_006b: ldsflda valuetype [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.WaveFormat SoundDetectorLast.Class1::wf
IL_0070: ldsflda valuetype [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.WaveFormat SoundDetectorLast.Class1::wf
IL_0075: call instance int16 [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.WaveFormat::get_Channels()
IL_007a: ldsflda valuetype [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.WaveFormat SoundDetectorLast.Class1::wf
IL_007f: call instance int16 [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.WaveFormat::get_BitsPerSample()
IL_0084: mul
IL_0085: ldc.i4.8
IL_0086: div
IL_0087: conv.i2
IL_0088: call instance void [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.WaveFormat::set_BlockAlign(int16)
IL_008d: ldsflda valuetype [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.WaveFormat SoundDetectorLast.Class1::wf
IL_0092: ldsflda valuetype [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.WaveFormat SoundDetectorLast.Class1::wf
IL_0097: call instance int16 [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.WaveFormat::get_BlockAlign()
IL_009c: ldsflda valuetype [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.WaveFormat SoundDetectorLast.Class1::wf
IL_00a1: call instance int32 [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.WaveFormat::get_SamplesPerSecond()
IL_00a6: mul
IL_00a7: call instance void [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.WaveFormat::set_AverageBytesPerSecond(int32)
IL_00ac: ldsflda valuetype [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.WaveFormat SoundDetectorLast.Class1::wf
IL_00b1: ldc.i4.1
IL_00b2: call instance void [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.WaveFormat::set_FormatTag(valuetype [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.WaveFormatTag)
IL_00b7: ldsflda valuetype [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.CaptureBufferDescription SoundDetectorLast.Class1::desc
IL_00bc: ldsfld valuetype [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.WaveFormat SoundDetectorLast.Class1::wf
IL_00c1: call instance void [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.CaptureBufferDescription::set_Format(valuetype [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.WaveFormat)
IL_00c6: ldsflda valuetype [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.CaptureBufferDescription SoundDetectorLast.Class1::desc
IL_00cb: ldc.i4.8
IL_00cc: ldsflda valuetype [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.WaveFormat SoundDetectorLast.Class1::wf
IL_00d1: call instance int16 [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.WaveFormat::get_BlockAlign()
IL_00d6: mul
IL_00d7: call instance void [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.CaptureBufferDescription::set_BufferBytes(int32)
IL_00dc: ldsfld valuetype [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.CaptureBufferDescription SoundDetectorLast.Class1::desc
IL_00e1: ldsfld class [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.Capture SoundDetectorLast.Class1::cap
IL_00e6: newobj instance void [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.CaptureBuffer::.ctor(valuetype [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.CaptureBufferDescription,class [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.Capture)
IL_00eb: stsfld class [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.CaptureBuffer SoundDetectorLast.Class1::buffer
IL_00f0: ldsfld class [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.CaptureBuffer SoundDetectorLast.Class1::buffer
IL_00f5: ldc.i4.1
IL_00f6: callvirt instance void [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.CaptureBuffer::Start(bool)
IL_00fb: ret
} // end of method Class1::initSound
.method public hidebysig static int32 modopt([mscorlib]System.Runtime.InteropServices.CallConvCdecl) TickMe() cil managed
{
.vtentry 2 : 1
.export [2] as TickMe
.maxstack 5
.locals init ([0] int32 average,[1] int32 i)
IL_0000: ldc.i4.0
IL_0001: stloc.0
IL_0002: ldc.i4.0
IL_0003: stloc.1
IL_0004: br.s IL_001f
IL_0006: ldloc.0
IL_0007: ldsfld class [mscorlib]System.Array SoundDetectorLast.Class1::samples
IL_000c: ldloc.1
IL_000d: ldc.i4.0
IL_000e: ldc.i4.0
int32,int32)
IL_0014: unbox.any [mscorlib]System.Int16
IL_0019: add
IL_001a: stloc.0
IL_001b: ldloc.1
IL_001c: ldc.i4.1
IL_001d: add
IL_001e: stloc.1
IL_001f: ldloc.1
IL_0020: ldc.i4.8
IL_0021: blt.s IL_0006
IL_0023: ldloc.0
IL_0024: ldc.i4.8
IL_0025: div
IL_0026: ldc.i4.s 10
IL_0028: div
IL_0029: ldc.i4.0
IL_002a: call int32 [mscorlib]System.Math::Max(int32,int32)
IL_002f: pop
IL_0030: ldc.i4.0
IL_0031: ret
} // end of method Class1::TickMe
.method public hidebysig specialname rtspecialname instance void .ctor() cil managed
{
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: ret
} // end of method Class1::.ctor
.method private hidebysig specialname rtspecialname static void .cctor() cil managed
{
.maxstack 8
IL_0000: ldc.i4.3
IL_0001: newarr [mscorlib]System.Int32
IL_0006: dup
IL_0007: ldtoken field valuetype '<PrivateImplementationDetails>{30E85D0D-9151-4165-8076-E6C64AE33575}'/'__StaticArrayInitTypeSize=12' '<PrivateImplementationDetails>{30E85D0D-9151-4165-8076-E6C64AE33575}'::'$$method0x6000004-1'
IL_000c: call void [mscorlib]System.Runtime.CompilerServices.RuntimeHelpers::InitializeArray(class [mscorlib]System.Array,valuetype [mscorlib]System.RuntimeFieldHandle)
IL_0011: stsfld int32[] SoundDetectorLast.Class1::SAMPLE_FORMAT_ARRAY
IL_0016: newobj instance void [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.DevicesCollection::.ctor()
IL_001b: stsfld class [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.DevicesCollection SoundDetectorLast.Class1::dc
IL_0020: newobj instance void [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.Capture::.ctor()
IL_0025: stsfld class [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.Capture SoundDetectorLast.Class1::cap
IL_002a: newobj instance void [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.CaptureBufferDescription::.ctor()
IL_002f: stsfld valuetype [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.CaptureBufferDescription SoundDetectorLast.Class1::desc
IL_0034: newobj instance void [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.WaveFormat::.ctor()
IL_0039: stsfld valuetype [Microsoft.DirectX.DirectSound]Microsoft.DirectX.DirectSound.WaveFormat SoundDetectorLast.Class1::wf
IL_003e: ret
} // end of method Class1::.cctor
} // end of class SoundDetectorLast.Class1
.class private auto ansi '<PrivateImplementationDetails>{30E85D0D-9151-4165-8076-E6C64AE33575}'
extends [mscorlib]System.Object
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.class explicit ansi sealed nested private '__StaticArrayInitTypeSize=12'
extends [mscorlib]System.ValueType
{
.pack 1
.size 12
} // end of class '__StaticArrayInitTypeSize=12'
.field static assembly valuetype '<PrivateImplementationDetails>{30E85D0D-9151-4165-8076-E6C64AE33575}'/'__StaticArrayInitTypeSize=12' '$$method0x6000004-1' at I_00002198
} // end of class '<PrivateImplementationDetails>{30E85D0D-9151-4165-8076-E6C64AE33575}'
.data cil I_00002198 = bytearray (
08 00 00 00 02 00 00 00 01 00 00 00)
If someone could help me solve this problem I'll be grateful.