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 3320702
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:58:29+00:00 2026-05-17T22:58:29+00:00

What is the proper way to link to functions in a C# DLL from

  • 0

What is the proper way to link to functions in a C# DLL from a C# application?

This is how my DLL looks:

namespace WMIQuery_Namespace
{
    public class WMIQuery
    {
        public static string GetPortName()
        {
            /* Does some stuff returning valid port name. */

            return string.Empty;
        }

        public static int ScanForAdapters()
        {
            /* Does some stuff returning valid adapter index. */

            return _index = -1;
        }
    }
}

This is how the interface in my application looks:

namespace MyApp_Namespace
{
    class MyApp_Class
    {
        internal static class WMIQuery
        {
            [DllImport("WMIQuery.dll")]
            internal static extern string GetPortName();

            [DllImport("WMIQuery.dll")]
            internal static extern int ScanForAdapters();
        }
    }
}

Everything compiles without any errors or warnings, but when I try to call these functions from my application this exception is thrown:

“Unable to find an entry point named
‘ScanForAdapters’ in DLL
‘WMIQuery.dll’.”

What am I doing wrong? I am aware that I can add WMIQuery as a reference, but I need to link it as an unmanaged DLL. Thanks.

  • 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-17T22:58:30+00:00Added an answer on May 17, 2026 at 10:58 pm

    If the DLL is a C# DLL, you don’t use P/Invoke to “link” to it.

    Just add it as a reference to your project, and add, at the top of the class where you want to use it:

    using WMIQuery_Namespace;
    

    You can then directly do:

    var port = WMIQuery.GetPortName();
    

    No need for any code in the “client” side at all…


    As for:

    but the requirements of the application require that it be loaded dynamically at run-time. Thanks.

    Realize that the assembly will not be loaded until the point in time that your application uses it. Assemblies in the CLR are not loaded at startup, but rather at the time the first type is used from within the assembly. There is no need to try to load it via P/Invoke in order to achieve late binding.

    If you don’t trust this, you can always use Assembly.Load and reflection to call the members, but Platform Invocation services will not work for loading a C# assembly.

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

Sidebar

Related Questions

Coming from a C/C++ background. What is the proper way to link a D
What's the proper way to add a literal text value from a field to
While searching for a proper way to trim non-breaking space from parsed HTML, I've
What is the proper way to use URL parameters? My URL is this: http://localhost:8080/#pg5?testing=abc
As I've haven't found a proper way to link program (writteln in c++) statically
Is there a proper/standard way? <a href=# onclick=function();>Link</a> vs <script> $(document).ready(function(){ $('#link1').click(function(){ ... });
What's the proper way to use custom callbacks with express.js functions? Here's an example:
I was looking a proper way to implment a ScaleAnimation. My purpose is to
Is there a proper way, equation or technique in general to say, My web
QUESTION: What is the proper way to use .get() in conjunction with .one() (or

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.