MDA Pinvoke StackImbalance

  • Thread starter Thread starter Bob
  • Start date Start date
B

Bob

Hi,
I down loaded a sample project which I can step through OK.
I took a couple of classes into my own project and when I step through the
above MDA triggers.
The trigger point is inside one of the imported classes as it tries a
windows call.
SendMessage(this.Handle, WM_ERASEBKGND, hDC, 0);

The declaration (which is part of the imported class) is

[DllImport("user32.dll", EntryPoint="SendMessageA")]

private static extern int SendMessage (IntPtr hwnd, int wMsg, IntPtr wParam,
object lParam);

I thought at first that it must be that the MDA can be turned off at project
level so the sample project was running without it. But the Framework help
indicates that it is either on or off at an environment level.

Any ideas on this would be appreciated.

thanks

Bob
 
I thought at first that it must be that the MDA can be turned off at project
level so the sample project was running without it. But the Framework help
indicates that it is either on or off at an environment level.

Any ideas on this would be appreciated.

It's because of the lParam parameter type. It's not correct to have it
declared as object, that marshals to a VARIANT by default. Try
changing it to an IntPtr and pass in IntPtr.Zero.


Mattias
 
Hi Mattias,
Spot On.
Any ideas why the downloaded project runs OK?
Has it in fact somehow got the PInvokeStack imbalance MDA turned off?
Also do you know where the 'bible' of WIN API calls is?
My searches have been unsuccessful.
thanks
Bob
 
| Hi Mattias,
| Spot On.
| Any ideas why the downloaded project runs OK?
| Has it in fact somehow got the PInvokeStack imbalance MDA turned off?
| Also do you know where the 'bible' of WIN API calls is?
| My searches have been unsuccessful.
| thanks
| Bob
|
| | > >I thought at first that it must be that the MDA can be turned off at
| project
| > >level so the sample project was running without it. But the Framework
| help
| > >indicates that it is either on or off at an environment level.
| > >
| > >Any ideas on this would be appreciated.
| >
| > It's because of the lParam parameter type. It's not correct to have it
| > declared as object, that marshals to a VARIANT by default. Try
| > changing it to an IntPtr and pass in IntPtr.Zero.
| >
| >
| > Mattias
| >
| > --
| > Mattias Sjögren [C# MVP] mattias @ mvps.org
| > http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
| > Please reply only to the newsgroup.
|
|

MDA's are only available in V2 (maybe the code is older or the author didn't
care about it), note MDA's are only enabled when running in the (managed)
debugger. But what's important is that the code is wrong and should be
corrected. The CLR tries hard to correct these stack imbalances at run-time,
but you incur a performance overhead and it's still possible that the CLR
can't correctly adjust the stack when the function returns from unmanaged
land.

Willy,
 
Hi Willy,
Thanks,
I agree totally with correcting the code.
But I was curious about the IDE behaviour difference.
Sample project must be V2 as IDE did not ask me to build a new project.
The project does seem to have brought its own settings with it. (IDE looks
different in that project, different project property screen layout, shift
f6 does not compile etc)
Maybe my understanding of MDA scope is flawed, perhaps it is scoped to
project level.
regards
Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top