CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Join Date
    Apr 2007
    Location
    Mars NASA Station
    Posts
    1,436

    DLL Library Question

    Hello to all expert,

    i have create a win32 console project, then dll project and empty project.

    Can anyone give me an explanation how to create a dll from native C++(class/Member function)?

    Code:
    #ifndef STOPWATCH
    #define STOPWATCH
    
    #include <string>
    #include <ctime>
    
    class stopwatch
    {
    private:
    	std::clock_t elapsed;
    public:
    	stopwatch();
    	~stopwatch();
    };
    
    
    
    /* 
    	Do not put definition in header file to avoid
    	multiple definition through include directive 
    	in object files
    */
    void myInitialize();
    
    #endif
    Code:
    #include <iostream>
    #include <sstream>
    #include <fstream>
    #include <vector>
    #include <ctime>
    
    #include "StopWatch.h"
    
    // =============================================
    stopwatch::stopwatch() : elapsed(std::clock())
    {
    }
    // =============================================
    stopwatch::~stopwatch()
    {
    	std::cout << "\nTotal ticks is " << std::clock() - elapsed;
    	std::cout << "\nTotal seconds is " << (std::clock() - elapsed)
    		/CLOCKS_PER_SEC;
    	// 1000 ticks == 1 second
    }
    // =============================================
    void myInitialize()
    {
    	//stopwatch sw;
    
    	std::string* ptr[90000];
    
    	for (int loop=0;loop<90000;++loop)
    	{
    		// 50% improvement over dynamic storage allocation
    	//	string s;
    		ptr[loop] = new std::string;
    	}
    }
    // =============================================
    The purpose of creating the library is to import to certain project with few clicks.

    Thanks for your help.
    Thanks for your help.

  2. #2
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: DLL Library Question


  3. #3
    Join Date
    Apr 2007
    Location
    Mars NASA Station
    Posts
    1,436

    Re: DLL Library Question

    I want to pack this class as DLL.
    Thanks for your help.

  4. #4
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: DLL Library Question

    Quote Originally Posted by Peter_APIIT View Post
    The purpose of creating the library is to import to certain project with few clicks.
    The "few clicks" imperative does not explain why the library has to be dynamically linked. Any comments?
    Best regards,
    Igor

  5. #5
    Join Date
    Apr 2007
    Location
    Mars NASA Station
    Posts
    1,436

    Re: DLL Library Question

    I not care whether the code is static link or dynamic link but i just care to pack this as library format.
    Thanks for your help.

  6. #6
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: DLL Library Question

    Well, finally you have to decide, LIB or DLL is your target.
    Then you create a project of corresponding type, include your class there and build.
    What step causes a confusion to you?
    Best regards,
    Igor

  7. #7
    Join Date
    Apr 2007
    Location
    Mars NASA Station
    Posts
    1,436

    Re: DLL Library Question

    I have create a static library(.Lib) but don't know how to import them to other project.


    I have did this Linker->General->Additional Library directories
    and Linker->Input->Additional Dependencies.

    This does not solve the problem.
    Thanks.
    Last edited by Peter_APIIT; January 17th, 2009 at 12:12 AM.
    Thanks for your help.

  8. #8
    Join Date
    Apr 2007
    Location
    Mars NASA Station
    Posts
    1,436

    Re: DLL Library Question

    Please help.
    Thanks for your help.

  9. #9
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: DLL Library Question

    This does not solve the problem.
    This does not explain where your problem is.
    Attached Files Attached Files
    Last edited by Igor Vartanov; January 19th, 2009 at 01:26 PM.
    Best regards,
    Igor

  10. #10
    Join Date
    Apr 2007
    Location
    Mars NASA Station
    Posts
    1,436

    Re: DLL Library Question

    I try to include the static library by settings this Linker->General->Additional Library directories(D:\C++\Library\StopWatch DLL\debug)

    and Linker->Input->Additional Dependencies (StopWatch.lib)

    but compiler complaint that it cannot find the path(undeclared identifier).

    The file format is object file library.
    Last edited by Peter_APIIT; February 11th, 2009 at 04:15 AM.
    Thanks for your help.

  11. #11
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: DLL Library Question

    Quote Originally Posted by Peter_APIIT View Post
    but compiler complaint that it cannot find the path(undeclared identifier).
    'Undeclared identifier' is a compile-time problem (typically, it's a missed header file) and has nothing to do with linker, library file paths, etc.
    Best regards,
    Igor

  12. #12
    Join Date
    Apr 2007
    Location
    Mars NASA Station
    Posts
    1,436

    Re: DLL Library Question

    Sorry to you, i have included the #include "StopWatch.h" header file but now the problem is
    Error 1 fatal error C1083: Cannot open include file: 'StopWatch.h': No such file or directory
    I didn't not include the StopWatch header file to that project.

    Any hints ?

    Thanks to you.
    Thanks for your help.

  13. #13
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: DLL Library Question

    Quote Originally Posted by Peter_APIIT View Post
    Sorry to you, i have included the #include "StopWatch.h" header file but now the problem is
    Error 1 fatal error C1083: Cannot open include file: 'StopWatch.h': No such file or directory
    I didn't not include the StopWatch header file to that project.

    Any hints ?
    A hint: learn C/C++ compiler basics, #include directive in particular.
    From MSDN:
    Quoted form
    This form instructs the preprocessor to look for include files in the same directory of the file that contains the #include statement, and then in the directories of any files that include (#include) that file. The preprocessor then searches along the path specified by the /I compiler option, then along paths specified by the INCLUDE environment variable.
    Best regards,
    Igor

  14. #14
    Join Date
    Apr 2007
    Location
    Mars NASA Station
    Posts
    1,436

    Re: DLL Library Question

    I try this #include <StopWatch.h> too but still compiler cannot find the file.

    Please help me.

    Thanks.
    Thanks for your help.

  15. #15
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: DLL Library Question

    Quote Originally Posted by Peter_APIIT View Post
    I try this #include <StopWatch.h> too but still compiler cannot find the file.
    Yeah, shooting into the dark is a funny game.

    From MSDN:
    Angle-bracket form
    This form instructs the preprocessor to search for include files first along the path specified by the /I compiler option, then, when compiling from the command line, along the path specified by the INCLUDE environment variable.
    Please help me.
    I wonder, did you really give a try to read the link I provided? I mean, read and think over?
    Best regards,
    Igor

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured