.NET Framework Bookmark and Share   
 index > 64-Bit .NET Framework Development > WaveIn using P/Invoke do not work on x64
 

WaveIn using P/Invoke do not work on x64

Hi,

My aplication works fine on x86. I dont get any errors, but when i tryrecord some sound on Vista x64 i get:

'NullReferenceException was unhandled
Object reference not set to an instance of an object.' at WaveInOpen Function.


My WaveIn declaration:
[DllImport(mmdll)]



public static extern int waveInOpen(out IntPtr phwi, int uDeviceID, WaveFormat lpFormat, WaveDelegate dwCallback, int dwInstance, int dwFlags);

This is how I use it:

WaveInHelper.Try(WaveNative.waveInOpen(out m_WaveIn, device, format, m_BufferProc, 0, WaveNative.CALLBACK_FUNCTION));

WaveFormat structure declaration:

    [StructLayout(LayoutKind.Sequential)]



    public class WaveFormat



    {



        public short wFormatTag;



        public short nChannels;



        public int nSamplesPerSec;



        public int nAvgBytesPerSec;



        public short nBlockAlign;



        public short wBitsPerSample;



        public short cbSize;







        public WaveFormat(int rate, int bits, int channels)



        {



            wFormatTag = (short)WaveFormats.Pcm;



            nChannels = (short)channels;



            nSamplesPerSec = rate;



            wBitsPerSample = (short)bits;



            cbSize = 0;







            nBlockAlign = (short)(channels * (bits / 8));



            nAvgBytesPerSec = nSamplesPerSec * nBlockAlign;



        }



    }



I've tried to modify declaration with IntPtr.Zero instead of '0'. Or changing 'WaveFormat lpFormat'(argument) into 'ref WaveFormat lpFormat', but then i get'error 32'(bad format), thenrecording will not run also on x86 anymore giving me Access Volation.

Also I've tried compile it for only for x86 or AnyCpu, but it gives no results.

I'm working on it some about 7 days and i can't go forwad.

Sorry for my English.

I would begrateful if anyone can help me, it's very important for me.

  • Edited byBad_Ray Saturday, September 05, 2009 5:55 PM
  •  
Bad_Ray

I got solution, my visual studio project file was broken, i create new project, recopy it, and i set x86 platform. Now everything works.

  • Marked As Answer byBad_Ray Saturday, September 05, 2009 5:54 PM
  •  
Bad_Ray

I got solution, my visual studio project file was broken, i create new project, recopy it, and i set x86 platform. Now everything works.

  • Marked As Answer byBad_Ray Saturday, September 05, 2009 5:54 PM
  •  
Bad_Ray

You can use google to search for other answers

Custom Search

More Threads

• Need help, cant get CAPICOM to work in a vb.net app on 64bit platform
• Cannot install .net 2003 on AMD Atholon 64bit 3000
• How to generate 64 bit executables with visual basic .net?
• ODBC - DSN only connections in x64? how? - Urgent -
• Need some suggestions about picking a 64 bit workstation
• Forms: Multi-Line text-box renders as disabled when mouse hovers over it.
• ActiveX Controls Throwing Errors
• Problem in dot net application on 64 bit platform
• Compiled Regexs on 64bit are very slow
• CrtIsValidHeapPointer vs. __DllMainCRTStartup@12 in VS2008 x64