Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. VC++ DLL throws error when call it from C#[EntryPointNotFound]

VC++ DLL throws error when call it from C#[EntryPointNotFound]

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialc++csharphelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 9845382
    wrote on last edited by
    #1

    Here i created in DLL project in vc++ 2008. Following are two code files lib.h and lib.cpp. lib.h

    #include "stdafx.h";

    class \_\_declspec(dllexport) test
    {
    public:
        test();
        static void  hello();
        static void  hello1();
    };
    
    class \_\_declspec(dllexport) test1
    {
    public:
        test1();
        void  hello\_test1();
        void  hello1\_test1();
    
    };
    

    lib.cpp

    #include "stdafx.h"
    #include "lib.h"
    #include void test::hello()
    {
    printf("Hello");
    }

    void test::hello1()
    {
        printf("Hello1");
    }
    
    void test1::hello\_test1()
    {
        printf("Hello\_test1");
    }
    
    void test1::hello1\_test1()
    {
        printf("Hello1\_test1");
    }
    

    stdafx.h

    #include "targetver.h"
    #define WIN32_LEAN_AND_MEAN
    // Windows Header Files:
    #include

    dllMain.cpp

    #include "stdafx.h"

    BOOL APIENTRY DllMain( HMODULE hModule,
    DWORD ul_reason_for_call,
    LPVOID lpReserved
    )
    {
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
    break;
    }
    return TRUE;
    }

    I have written C# code to call the method of test and test1 classes: consoleApp

    [DllImport("lib.dll" )]
    public static extern void hello();

    \[DllImport("lib.dll")\]
    public static extern void hello1();
    
    \[DllImport("lib.dll")\]
    public static extern void hello\_test1();
    
    \[DllImport("lib.dll")\]
    public static extern void hello1\_test1();
    

    static void Main()
    {
    hello();
    hello1();
    hello_test1();
    hello1_test1();
    Console.ReadKey();
    }

    when i run above code i have got following error: EntryPointNotFoundException: Unable to find an entry point named 'hello' in DLL 'lib.dll' 1****<-Click 1 for image I know about how to call function only(without using Class) of vc++ DLL from C# but i don't know how to call method of any class and how to code that in proper way in vc++. I know somewhere is mistake in my above code, please experts guide me about my mistake because i tried all from my side. If anyone has full example like above then suggest me. Thanks in advance..

    Richard Andrew x64R 1 Reply Last reply
    0
    • U User 9845382

      Here i created in DLL project in vc++ 2008. Following are two code files lib.h and lib.cpp. lib.h

      #include "stdafx.h";

      class \_\_declspec(dllexport) test
      {
      public:
          test();
          static void  hello();
          static void  hello1();
      };
      
      class \_\_declspec(dllexport) test1
      {
      public:
          test1();
          void  hello\_test1();
          void  hello1\_test1();
      
      };
      

      lib.cpp

      #include "stdafx.h"
      #include "lib.h"
      #include void test::hello()
      {
      printf("Hello");
      }

      void test::hello1()
      {
          printf("Hello1");
      }
      
      void test1::hello\_test1()
      {
          printf("Hello\_test1");
      }
      
      void test1::hello1\_test1()
      {
          printf("Hello1\_test1");
      }
      

      stdafx.h

      #include "targetver.h"
      #define WIN32_LEAN_AND_MEAN
      // Windows Header Files:
      #include

      dllMain.cpp

      #include "stdafx.h"

      BOOL APIENTRY DllMain( HMODULE hModule,
      DWORD ul_reason_for_call,
      LPVOID lpReserved
      )
      {
      switch (ul_reason_for_call)
      {
      case DLL_PROCESS_ATTACH:
      case DLL_THREAD_ATTACH:
      case DLL_THREAD_DETACH:
      case DLL_PROCESS_DETACH:
      break;
      }
      return TRUE;
      }

      I have written C# code to call the method of test and test1 classes: consoleApp

      [DllImport("lib.dll" )]
      public static extern void hello();

      \[DllImport("lib.dll")\]
      public static extern void hello1();
      
      \[DllImport("lib.dll")\]
      public static extern void hello\_test1();
      
      \[DllImport("lib.dll")\]
      public static extern void hello1\_test1();
      

      static void Main()
      {
      hello();
      hello1();
      hello_test1();
      hello1_test1();
      Console.ReadKey();
      }

      when i run above code i have got following error: EntryPointNotFoundException: Unable to find an entry point named 'hello' in DLL 'lib.dll' 1****<-Click 1 for image I know about how to call function only(without using Class) of vc++ DLL from C# but i don't know how to call method of any class and how to code that in proper way in vc++. I know somewhere is mistake in my above code, please experts guide me about my mistake because i tried all from my side. If anyone has full example like above then suggest me. Thanks in advance..

      Richard Andrew x64R Offline
      Richard Andrew x64R Offline
      Richard Andrew x64
      wrote on last edited by
      #2

      There are two main issues to deal with here. 1. If you want to call functions like that in a C++ DLL, you shouldn't put them inside classes. 2. There is an issue called C++ Name Mangling. This is where the linker exports the functions with additional characters that describe the function signature. To call the functions by their names directly, you must place the definitions inside an "extern C" declaration like so:

      extern "C"
      {
      void Hello()
      { printf("Hello");}

      void Hello1()
      { printf("Hello 1");}
      

      }

      The difficult we do right away... ...the impossible takes slightly longer.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups