Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3492294
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:44:27+00:00 2026-05-18T11:44:27+00:00

As a C# developer, I think many of us have the experience as calling

  • 0

As a C# developer, I think many of us have the experience as calling unmanaged code from managed code.

What is the most difficult problem you’ve ever faced when dealing with interoperability between managed code and unmanaged code? (You had better give code examples such as C++ function signature and C# wrappers)

How do you debug the runtime error since no high level debug information provided by visual studio when dealing with the calling?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T11:44:28+00:00Added an answer on May 18, 2026 at 11:44 am

    In general, finding an authoritative reference for P/Invoke declarations is difficult if you don’t know enough about C to get the declaration right. There are a lot of bad declarations out on the Internet. The typical traps are VB6 declarations, there are a lot of them out there, where arguments that are really int are declared as Long. Long is the 32-bit integral type in VB6, Integer is 16-bit for historical reasons.

    Another wide-spread mistake is using int where IntPtr is required. These declarations work fine in 32-bit mode but misbehave in 64-bit mode. Especially troublesome are functions that take 4 or less arguments, the wrong argument type doesn’t generate the PInvokeStackImbalance MDA warning because the first 4 function arguments are passed in CPU registers. This bug tends to bite long after the author declared the job done, pretty hard to get back into it and diagnose the trouble.

    The next hassle is the tedium of declaring and maintaining either P/Invoke declarations or C++/CLI wrappers. When the unmanaged API is big, you’ll end up writing a heck of a lot of them. Each of them ready to give you a hard to diagnose runtime error when you get it subtly wrong.

    The truly hard interop is with COM servers that have IUnknown based interfaces. Such servers don’t have a type library so there’s no opportunity to use Tlbimp.exe to auto-generate the interop library. You have to re-declare the interfaces in your C# code and make sure you get [Guid] and the method declarations right. The lack of support for multiple inheritance requires jumping through extra hoops when the interface inherits from an intermediate IUnknown based interface. The problem that this author incorrectly calls the ‘inheritance tax’.

    These kind of servers are way more common then meets the eye. Just about anything you’d want to do with the shell (explorer.exe) is IUnknown based for example. So are the Vista and Win7 extensions, ably wrapped by the Windows API Code Pack btw.

    And yes, error handling. Way too much unmanaged code out there that return nothing but an unfriendly error code like E_FAIL or E_UNEXPECTED. And doesn’t implement IErrorInfo so all you got is an unhelpful generic message to look at. Or APIs that return BOOL to indicate failure, inviting a programmer to simply ignore the return value. And AccessViolation or Fatal Engine Execution Error, unmanaged code blowing up in your face without leaving any breadcrumb to find out what went wrong. This isn’t particular to C# interop, such code is hard for anybody to use.

    Other than that, it usually is pretty simple to make it work. The P/Invoke marshaller and the COM interop support in .NET are truly excellent and significantly better than what’s available in other VMs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From the moment I have faced Python, the only thing I can say for
I think many developers know that uncomfortable feeling when users tell them that The
From a web developer point of view, what changes are expected in the development
I am from an XP background. I know the process very well and have
I am a reasonably experienced C# developer (about 5 year experience) that has recently
I have an application where many unit tests use a real connection to an
I've always had a thing for C++/CLI. Maybe because not many developers use it...
Lots of developers think that testing private methods is a bad idea. However, all
I just saw a really cool WPF twitter client that I think is developed
I think it's better to release the version of the software which your developers

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.