Reputation: 562
i have two VC++ projects under same solution prj1(console based) and prj2(Form based). I want to use self defined functions in "prj1" (add(int a, int b)) in "prj2" on button click. I dont want to create new project i.e. I only want to combine the existing projects. I'm using Visual Studio 2005 can any body help me out.
Upvotes: 1
Views: 3023
Reputation: 18441
It all depends on dependency-level of function add
. If it is self contained function (like sorting), you can striaghtaway use in another project as suggest by Chad in point 2. If function has dependency (forms, classes other stuff), you may be in trouble. You may need to share all that into another project too. In that case you can put all of that shared code into a DLL (or a static-library), remove from both projects, and add reference of that DLL/LIB in both projects.
add
and other relevant functions/classUpvotes: 0
Reputation: 19052
It's not possible to export the functions in place if both projects are generating executable files (as in one console app and one Windows app).
Since you've already stated you don't want an additional project there are two options:
Option 2 is preferred, as it helps with code maintenance having one location for that code.
The best option is to abstract the shared code into a library that can be linked in with both projects, but you've already stated that is not a viable option. I would ask -- why not?
Upvotes: 2
Reputation: 3826
Sorry for the stupid question but does VS 2005 have the concept of a Solution file? I know in C# you can add multiple projects to one solution and as long as you access them with the right namespace (and of course the classes/methods are public and visible) you can use them after some instantiation. Maybe VS 2005 you can just load the two projects in a solution and get at them that way? but its been a long while since I have used VS C++ 2005
Upvotes: 0