Click to See Complete Forum and Search --> : DLL Library Question


Peter_APIIT
January 14th, 2009, 03:11 AM
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)?


#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





#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.

Andreas Masur
January 14th, 2009, 07:38 AM
Exporting from a DLL (http://msdn.microsoft.com/en-us/library/z4zxe9k8.aspx)

Peter_APIIT
January 15th, 2009, 04:06 AM
I want to pack this class as DLL.

Igor Vartanov
January 15th, 2009, 05:41 AM
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?

Peter_APIIT
January 15th, 2009, 07:11 AM
I not care whether the code is static link or dynamic link but i just care to pack this as library format.

Igor Vartanov
January 15th, 2009, 07:46 AM
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?

Peter_APIIT
January 16th, 2009, 10:30 PM
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.

Peter_APIIT
January 19th, 2009, 03:18 AM
Please help.

Igor Vartanov
January 19th, 2009, 12:10 PM
This does not solve the problem.This does not explain where your problem is.

Peter_APIIT
February 11th, 2009, 03:09 AM
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.

Igor Vartanov
February 11th, 2009, 07:10 AM
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.

Peter_APIIT
February 13th, 2009, 03:20 AM
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.

Igor Vartanov
February 13th, 2009, 06:20 AM
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 (http://msdn.microsoft.com/en-us/library/36k2cdd4(VS.71).aspx) 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.

Peter_APIIT
February 14th, 2009, 05:43 AM
I try this #include <StopWatch.h> too but still compiler cannot find the file.

Please help me.

Thanks.

Igor Vartanov
February 14th, 2009, 10:44 AM
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?

Peter_APIIT
February 19th, 2009, 05:53 AM
Where to set the /I compiler option in MS VS 2005 ?

I really need help.

Thanks.

Igor Vartanov
February 19th, 2009, 09:18 AM
See project properties