none
Windows form application linking with DLL RRS feed

  • Question

  • Hi,

    i have a windows form application(vs2015) in c++. i want to link DLL to this application and use dll functions.

    i have a class library project(.dll)

    //test.h  //header file

    #include "test1.h" //structures used are defined here

    namespace test

    {

    class Class1

    {

    public :

    static int write(WRITE_TEST writetest);

    };

    }

    //#include test.cpp

    #include "test.h"

    namespace test{

    int Class1::write(WRITE_TEST writetest){

    //implementation.

    }

    Above code built as DLL.

    i have a windows form application. i added the above dll as reference in this form application. Also included the dll path in additional include directories.

    #include "test.h"

        test::Class1::write(writetest); //calling function from dll.

    but i get the error as unresolved token(0A000499) public:static int _cdecl  test::Class1::write(struct ).

    Anything am missing for calling the function from DLL?

    Thursday, February 23, 2017 7:33 AM

All replies

  • i have a windows form application(vs2015) in c++. i want to link DLL to this application and use dll functions...

    ...

    Also included the dll path in additional include directories.


    Why do that? The additional include directories property tells the compiler
    where to look for additional header files. (As in #include statements.)

    Read this article:

    Using Unmanaged C++ Libraries (DLLs) in .NET Applications
    https://www.codeproject.com/Articles/14180/Using-Unmanaged-C-Libraries-DLLs-in-NET-Applicatio

    And this thread:

    how to adda native C++ dll in a Windows Form C++.NET project in visual studio?
    http://stackoverflow.com/questions/8711870/how-to-adda-native-c-dll-in-a-windows-form-c-net-project-in-visual-studio

    - Wayne

    • Proposed as answer by Baron Bi Thursday, February 23, 2017 9:19 AM
    • Unproposed as answer by Shwetha s Friday, February 24, 2017 4:22 AM
    Thursday, February 23, 2017 8:16 AM
  • Hi Wayne,

    Thank you for the response.

    i removed the dll path from additional include directories.

    Also included in test.h, included TEST_LIBRARY in preprocessor definitions.

    //test.h

    #ifdef TEST_LIBRARY

    #define LIBRARY_EXPORT _declspec(dllexport)

    #else

    #define LIBRARY_EXPORT _declspec(dllimport)

    #endif

    #include "test1.h" //structures used are defined here

    namespace test

    {

    class LIBRARY_EXPORT Class1

    {

    public :

    static int write(WRITE_TEST writetest);

    };

    }

    Still i get same error

    Thursday, February 23, 2017 9:29 AM
  • Are you trying to do the static linking or the dynamic linking of the library?

    It seems you are dynamically linking the library, so in that case you do not need to add this "TEST_LIBRARY in preprocessor definitions". simply load the library using Loadlibrary() and GetProcAddress() you can access the methods with the help of function pointers.


    Thanks & Regards, Mayank Agarwal

    Thursday, February 23, 2017 9:56 AM
  • Hi Mayank,

    Thank you for the response.

    Can I get any example on how to access the class member (which is inside the dll) using GetProcAddress();

    Regards,

    Shwetha

    Thursday, February 23, 2017 1:38 PM
  • Hi Shwetha s,

    thanks for posting here.

    >>Can I get any example on how to access the class member (which is inside the dll) using GetProcAddress();

     To explicitly link to a DLL, an application could:
    • Call LoadLibrary (or a similar function) to load the DLL and obtain a module handle.

    • Call GetProcAddress to obtain a function pointer to each exported function that the application wants to call. Because applications are calling the DLL's functions through a pointer, the compiler does not generate external references, so there is no need to link with an import library.

    • Call FreeLibrary when done with the DLL.

    Here is a example for you as a reference.

    https://msdn.microsoft.com/en-us/library/windows/desktop/ms686944(v=vs.85).aspx

    Hope this could be help of you.

    Best Regards,
    Sera Yu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, February 24, 2017 6:51 AM
  • Hi Sera Yu,

    Thanks for the response.

    But can we access the class member functions within DLL in this way?

    or can not it be accessed by adding reference as in following link:

    https://msdn.microsoft.com/en-us/library/ms235636.aspx

    • Edited by Shwetha s Friday, February 24, 2017 12:03 PM
    Friday, February 24, 2017 7:23 AM

  • But can we access the class member functions within DLL in this way?

    or can not it be accessed by adding reference as in following link:

    https://msdn.microsoft.com/en-us/library/ms235636.aspx

    Have you properly defined TEST_LIBRARY in your DLL project, and not in your client project?

    If you have doe this, your code should work I think.


    David Wilkinson | Visual C++ MVP

    Friday, February 24, 2017 3:36 PM
  • Hi David,

    Yes. i have defined TEST_LIBRARY in the DLL project.

    Saturday, February 25, 2017 4:43 AM
  • i have a windows form application(vs2015) in c++. i want to link DLL to this application and use dll functions.

    i have a windows form application. i added the above dll as reference in this form application.

    but i get the error as unresolved token(0A000499) public:static int _cdecl  test::Class1::write(struct ).


    When you say: "i added the above dll as reference in this form application."

    what *exactly* did you add and how?

    If you mean you added the *.dll file under References for the project,
    then that isn't going to help at build time. The dll itself is only used
    at run time, when it must be on the search path of the executing program.

    For the build you should add the *.lib file that was created with the dll
    file to the References. That is an *import* library that has the exports
    of the associated dll listed. (Don't confuse it with a static lib.)
    It should be found in the same directory as the dll.

    - Wayne

    Sunday, February 26, 2017 7:09 AM
  • Hi all,

    i added a .def file in the Dll, And also included the Dll .lib file in the application.

    Issue solved.

    • Proposed as answer by Baron Bi Wednesday, March 1, 2017 2:57 AM
    Tuesday, February 28, 2017 7:02 AM
  • Please mark the thread closed by selecting the appropriate response.
    Tuesday, February 28, 2017 5:17 PM