Export methods from a dll in C ++

1

I have a problem, my dll has not exported any methods for me to use in other programs.

I did as follows:

namespace integration {

    class RESTRequest {
        public:
            __declspec(dllexport) string GetPing(char* ping);
        private:
            static void MarshalString(String ^ s, string& os);
    };

}

It's compiling cool, but when I try to access ddl with a java program, I get this error:

Exception in thread "main" java.lang.UnsatisfiedLinkError: Error looking up function 'GetPing': The specified procedure could not be found.

For me the export was done with __declspec(dllexport) in the method, but by the way it did not work only with it, do I have to add some more deltalhe in the dll?

    
asked by anonymous 28.01.2017 / 21:38

1 answer

1

Visual Studio 2005 compiler (used at the command line)

DLL

#include <iostream>
using namespace std;

namespace N
{
    class __declspec(dllexport) C
    {
      public:
         void display();
         static C* createNewC() { return new C; }
   };
}

void N::C::display()
{
   cout << "*\n";
   cout << "* hello from N::C::display\n";
   cout << "*\n";
}

TEST

namespace N
{
   class __declspec(dllimport) C
   {
      public:
         void display();
         static C* createNewC();
   };
}

int main()
{
   N::C* c = N::C::createNewC();
   c->display();
}

DLL COMPILATION

Wed  1 Feb 2017 04:52:00  >> { F:\projects\misc }                                  
$ cl /EHsc /LD testdll.cpp                                                         
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for 80x86   
Copyright (C) Microsoft Corporation.  All rights reserved.                         

testdll.cpp                                                                        
Microsoft (R) Incremental Linker Version 8.00.50727.762                            
Copyright (C) Microsoft Corporation.  All rights reserved.                         

/out:testdll.dll                                                                   
/dll                                                                               
/implib:testdll.lib                                                                
testdll.obj                                                                        
Creating library testdll.lib and object testdll.exp                             

TEST COMPILATION

$ cl /EHsc testdllmain.cpp testdll.lib                                                
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for 80x86      
Copyright (C) Microsoft Corporation.  All rights reserved.                            

testdllmain.cpp                                                                       
Microsoft (R) Incremental Linker Version 8.00.50727.762                               
Copyright (C) Microsoft Corporation.  All rights reserved.                            

/out:testdllmain.exe                                                                  
testdllmain.obj                                                                       
testdll.lib                                                                           

EXECUTION OF THE TEST

Wed  1 Feb 2017 04:45:04  >> { F:\projects\misc }                                     
$ testdllmain.exe                                                                     
*                                                                                     
* hello from N::C::display                                                            
*                                                                                     
    
01.02.2017 / 19:56