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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:46:14+00:00 2026-06-12T01:46:14+00:00

I am trying to use DLLImport for using Win32 dll method in C#. Win32

  • 0

I am trying to use DLLImport for using Win32 dll method in C#.

Win32 dll C++
// .h file

#ifdef IMPORTDLL_EXPORTS
#define IMPORTDLL_API __declspec(dllexport)
#else
#define IMPORTDLL_API __declspec(dllimport)
#endif

// This class is exported from the ImportDLL.dll
class IMPORTDLL_API CImportDLL {
public:
    CImportDLL(void);
    // TODO: add your methods here.
    int Add(int a , int b);
};

extern IMPORTDLL_API int nImportDLL;

IMPORTDLL_API int fnImportDLL(void);
IMPORTDLL_API int fnMultiply(int a,int b);

// .cpp file

// ImportDLL.cpp : Defines the exported functions for the DLL application.
//

#include "stdafx.h"
#include "ImportDLL.h"


// This is an example of an exported variable
IMPORTDLL_API int nImportDLL=0;

// This is an example of an exported function.
IMPORTDLL_API int fnImportDLL(void)
{
    return 42;
}

IMPORTDLL_API int fnMultiply(int a , int b)
{
    return (a*b);
}

Once i build this i get ImportDLL.dll

Now i create Windows Application and add this dll in debug folder and try to use this method using DLLImport

[DllImport("ImportDLL.dll")]
 public static extern int fnMultiply(int a, int b);

And I try to call this in C#
int a = fnMultiply(5, 6); // This line gives error Unable to find an entry point

Can any body tell what i am missing?
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-06-12T01:46:15+00:00Added an answer on June 12, 2026 at 1:46 am

    If you are exporting a C function from a native DLL, you may want to use the __stdcall calling convention (which is equivalent to WINAPI, i.e. the calling convention used by most Win32 API C-interface functions, and which is the default for .NET P/Invoke):

    extern "C" MYDLL_API int __stdcall fnMultiply(int a, int b)
    {
        return a*b;
    }
    
    // Note: update also the .h DLL public header file with __stdcall.
    

    In addition, if you want to avoid name mangling, you may want to export using .DEF files.
    e.g. Add a .DEF file to your native DLL project, and edit its content something like this:

    LIBRARY MYDLL
    EXPORTS
      fnMultiply @1
      ...
    

    (You can use the command line tool DUMPBIN/EXPORTS, or a GUI tool like Dependency Walker, to check the actual name with which the function is exported from the DLL.)

    Then you can use P/Invoke like this from C#:

    [DllImport("MyDLL.dll")]
    public static extern int fnMultiply(int a, int b);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use native dll, using DllImport. And I receive such error. System.DllNotFoundException:
I am trying to use the function PathCanonicalize using DllImport (PInvoke) on a 64
In a *.cpp file, trying to use a third party lib: #define DLL_IMPORT #include
I have created a minidump using win32 api [DllImport(DbgHelp.dll, SetLastError = true)] private static
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
I am trying to create an offline registry in memory using the offreg.dll provided
I am using C# in Mono and I'm trying to use pinvoke to call
I am currently trying to use a simple C++ DLL in a C# program
I´m trying to call a method that is in a C++ dll declarated as
Trying to access an old c++ dll from c# using Dll Import. Been searching

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.