views:

74

answers:

2

P/Invoke on x64 null reference exceptions

I get null reference exceptions when I try to compile for x64 in .NET code that makes use of platform invocation services to call unmanaged code in dlls. Am I missing something obvious here?

e.g. call to

Private Declare Function waveOutOpen Lib "winmm.dll" (ByRef lphWaveOut As Int32, ByVal uDeviceID As Int32, ByRef lpFormat As WAVEFORMATEX, ByVal dwCallback As WaveDelegate, ByVal dwInstance As Int32, ByVal dwFlags As Int32) As Int32

fails in:

full code here: http://stackoverflow.com/questions/2320860/waveout-sometimes-memory-issue

A: 

There is not 64 bit version of that unmanaged dll. The 32 bits version gets called and of course things don't really align?

Lars Truijens
+2  A: 

Are you maybe using a bunch of int (fixed-size 32 bits) where in fact an IntPtr (size varies depending on platform) would be required?

Lucero
perhaps this might be it
PeanutPower