Click here to Skip to main content
15,900,108 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi all,
I want to access a class which is located in different directory or project from another project without copying the class files. I don't know this is possible or not. Please help me.

Thanks in advance.
Posted

You need to access the source code, or a compiled version of it in a dll. Your code plainly can't create a class it does not know about.
 
Share this answer
 
Comments
virus131 12-Jul-11 2:54am    
Thanks for your reply. Can't we access it by setting path of class in our code or something like that. Please guide me.
I think you want to add a cpp file in your current project.If its is,
Note:This procedure is for VS2005.But i think same for vs6 also.

1. Right click on your current project tree item in solution explorer.
2. select ADD->Existing Item.
3.add cpp file and corresponding .h file.Then they will be added to your project.
 
Share this answer
 
Comments
virus131 12-Jul-11 3:35am    
Thank you for reply, but I don't want to do this, I know the procedure you have suggested. But I want to link the class (which is present in one directory) with my working class (present in another directory). I know about DLLs, but I don't want to use it. Can I do it by setting ClassPath. I have no idea about this. Please help me if you got my question.

Thanks again.
Stefan_Lang 12-Jul-11 6:35am    
ClassPath is not a C++ concept.

In C++ there are basically two ways to reuse classes: either you add it to your project, or you put it in a DLL, or a static Lib.

There are other concepts based on the idea of publishing classes to the system. E. g. in Windows applications can be 'automated' via a published interface. Most applications from MS such as Excel have an automation interface. You can learn more about it by googling for that.

I think ActiveX works similarly, and maybe .NET as well, but I have no experience with either.

Technically though, DLLs do exactly the same! The only difference is that it's harder to use a DLL from another language. So if you're not trying to access a class from another language, I see no reason at all to not use a DLL.
virus131 12-Jul-11 7:06am    
Thanks a lot for your answer, it's really helpful. Thanks again.
In addition to what was already suggested, you can also make your own library location (with headers and source) and include it under "Additional Include Directories". This will allow you to access the headers using #include <header_name.h>.
 
Share this answer
 
v2
if you want to use that specific class two solution is suggested

solution 1:
#include "{FilePath}/FileName.h"

solution 2:
Open your project property. Add the the header file path(excluding header file name) to your project Property page, under C/C++ Tree Link or may be TAB and add your path to Additional Include Directories
and then include like a normal header file like below:
#include <filename.h>
#include "FileName.h"

Another issue

> if you dont add the cpp file that define the functions you will get a linking error after. but compilation will be okay.
> if you have do not have cpp file then you must have to have either library or dll file or both.
>> if library file add the corresponding lib directory using property page or specifically add the library file with the project.
> if you neither lib nor cpp but dll, the process will be way different. I dont know enough to publish that issue online. help yourself out.
 
Share this answer
 
v2
Comments
virus131 13-Jul-11 2:41am    
Hi Albert and johny10151981, thanks a lot for the reply, I tried suggested answer but it's giving the error- error LNK2001: unresolved external symbol __this call. Please help me if you know about this error.

Thanks.
Mohibur Rashid 13-Jul-11 2:52am    
I already told you that you will get this error

1. add the cpp file or lib file into your project

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900