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

  • Home
  • SEARCH
  • 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 7188209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:01:19+00:00 2026-05-28T19:01:19+00:00

What is Platform Invoke (P/Invoke)? What does it mean to be performing a P/Invoke?

  • 0

What is Platform Invoke (P/Invoke)?


What does it mean to be performing a P/Invoke? Is it calling an external dll? e.g.:

[DllImport("coredll.dll", SetLastError=true)]
private static extern bool SHGetSpecialFolderPath(
      int hwndOwner, 
      string lpszPath,
      ceFolders nFolder,
      bool fCreate);

Is that what P/Invoke means: to use the [DllImport] attribute?

Is there anything else that can be considered a P/Invoke?

What about [ComImport]? e.g.:

[System.Runtime.InteropServices.ComImport]
[Guid("F8383852-FCD3-11d1-A6B9-006097DF5BD4")]
public class ProgressDialog
{
}

Note: This COM class (F8383852-FCD3-11d1-A6B9-006097DF5BD4) can be found in

HKEY_CLASSES_ROOT\CLSID\{F8383852-FCD3-11d1-A6B9-006097DF5BD4}
      (default)       %SystemRoot%\system32\shell32.dll
      ThreadingModel  Both

i could also construct a native ADO Recordset object with the code:

[System.Runtime.InteropServices.ComImport]
[Guid("00000535-0000-0010-8000-00AA006D2EA4")]
public class Recordset
{
}

Object rs= new Recordset();

Is that considered P/Invoke?

If we choose to say “P/Invoke is bad”, is ComImport as “bad” as DllImport?

What is Platform Invoke (P/Invoke)?


Update: From MSDN:

Platform Invoke Tutorial

Platform Invocation Services (PInvoke) allows managed code to call
unmanaged functions that are implemented in a DLL.

There are two ways that C# code can directly call unmanaged code:

  • Directly call a function exported from a DLL.
  • Call an interface method on a COM object (for more information, see COM Interop Part 1: C# Client Tutorial).

i think i may have answered my own question.


It’s a year and a half later. Now that nobody is paying attention to the question, and nobody has it favorited, i can say that the answer i accepted is wrong. P/Invoke is short for Platform Invoke. It is a mechanism where managed code operating inside the CLR can call unmanaged native (i.e. platform) code. This is nearly always done by calling code that resides in a native dll. COM dlls are native code; they just follow a strict structure to allow many different compilers to call them.

And Platform Invoke is bad. It bypasses all garbage collection, and depends on the platform (i.e. my 32-bit CLR process cannot load a 64-bit dll, my application written for Android cannot work on Windows, my application written for functionality on Windows 8 won’t work on Windows XP).

  • 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-28T19:01:22+00:00Added an answer on May 28, 2026 at 7:01 pm

    No, they are not the same. P/Invoke (platform invoke) always involves calling native DLLs directly using the CLR functionality. “Native DLLs” means any DLL that expoes extern "C" functions. Managed DLLs don’t let you expose them; such a DLL is typically written in C/C++. The give-away signature of P/Invoke in managed code is a DllImport attribute (or extern function in C#). Reading the P/Invoke page gives no mention of COM anywhere.

    Using ComImport is for the purpose of creating a custom interop assembly (i.e. something hand-crafted rather than a PIA automatically generated by TlbImp), and uses inherent CLR functionality that is quite independent from the P/Invoke functionality, and specific to COM.

    The similarities lie in that both these methods are used for interoperating with unmanaged code. Support for both is baked into the CLR, and although in theory one could use the Windows API to do COM interop completely manually in managed code, it makes no sense when .NET provides a structure means for you, in terms of primary or custom interop assemblies as well as lower-level support in System.ComponentModel.

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

Sidebar

Related Questions

What's the current status of Mono 's Platform Invoke implementation on Linux and on
I have code that uses methods from the SSPI dll (security.dll) via P/Invoke, which
As we know Silverlight does not allow private reflection. Still, I have a public
I created a cross-platform DLL in C++ that compiles on both Windows and Mac
For example, the flash platform provides the flash.debugger.enterDebugger() API call that does the job:
Where does the pointer returned by calling string::c_str() point to ? In the following
I'm trying to do some multi-monitor stuff using Platform Invoke. I've been using http://pinvoke.net
Platform: Windows XP Development Platform: VB6 When trying to set an application title via
Platform Builder is a tool for building a Windows CE Operating system on your
platform: django 1.0, google app engine, app-engine-patch , python 2.5.4 i am tring to

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.