Thursday, July 30, 2009

How can i use third party library (.lib) file in a DOS C++ program using Borland Turbo C++ 3.1?

There are three things to do and a couple of points to check.





1). If the library is distributed in header and object code or as a premade .lib file, you'll need to simply include the header file in your project in appropriate places, add the object to a .lib file using tlib if needed, and add the library file in by the correct switch at link time.





2). Some .lib files will have a different format that isn't compatible with Borland products. These may be useful if source is included for the entire library. Otherwise, contact the vendor to get a compatible version or the source code to be compiled under your setup.





3). Some libraries are distributed as open source and must be compiled for use. Simply compile to object and then use tlib from Borland to create a new library file(.lib). Remember to include the correct header file(s) in any case.





The only other problems could arise from directory conflicts. Some libraries will need to be manually linked in with switches to use that particular file. Sometimes the header should be included using the double quotes and a filespec rather than by placing the new header in the include directory. Watch for naming conflicts, especially if using a C library since they weren't written using the new namespace standards. I hope this gets you going.


Where's a good place to learn how to program with graphics in C?

I already understand the basics of C, and I have a windows.h library, can you recommend a website where I can learn to program with graphics?

Where's a good place to learn how to program with graphics in C?
www.opengl.org/


Using Windows.h in C++?

hi, I'm a new c++ programmer who's trying to learn more about windows programming. I'm currently working with Visual C++ 5.0 Express and I've downloaded then installed the Platform SDK package. Unfortunately, I'm still having trouble including the windows.h package. I've been told that all I need to do is include the correct libraries..I just have no idea how to do that yet %26gt;%26lt;. Any help would be greatly appreciated. Thanks in advance.

Using Windows.h in C++?
The compiler doesn't know where to find windows.h. You can either put the whole path in front of the file name, or you can teach VC++ where to look. Eventually you'll need to link to the lib files too, so may as well configure VC++ to know where everything is...





I don't have 5.0 Express, so I can't tell you exactly what menus to look for. In my version of VC++, it's under Tools\Options. Tab over to directories, and add the include and lib directories for your SDK, and also the directories for your VC++ installation.





Here's an example, but you'll need to find the appropriate paths on your machine (hint. Just search for Windows.h, then copy the path)





Include files:


C:\Program Files\Microsoft SDK\Include


C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE


(plus I have lots more)





Lib files:


C:\Program Files\Microsoft SDK\Lib


C:\Program Files\Microsoft Visual Studio\VC98\LIB


(etc.)
Reply:#include %26lt;windows%26gt;





I don't use VC++ so I'm not sure what you're seeing...but in Borland and Metrowerks it really is as simple as the above.
Reply:use #include %26lt;windows.h%26gt;





windows is in include folder path .. not in the project..

send flowers

C++ coding problem?

we're learning functions in my C++ class, he's given us function main, we're to write sub-functions that'll complete the task libraries are just iostream. I need to return a value to be stored in the variable userInput, but i can't think of a way to do that without modifying the function main (which i'm not allowed to do) or adding a global variable(which i'm not allowed to do) I don't need the code, just a hint (sorry yahoo answers removes my spacing before my code)





// function get Input has already been declared





int main (void)


{


int userInput;


char letter grade;


char gradeSign;





cout %26lt;%26lt; "input number between 1 and 100\n (an invalid value terminates the program)\n";





while (getInput (userInput))


{


//unrelavant code that uses the variable userInput


}


}





//function i've written so far


int getInput (int getInputVar)


{


cout %26lt;%26lt; "Numeric grade: ";


cin %26gt;%26gt; getInputVar;


if (cin.fail() || getInputVar %26lt;0 || getInputVar %26gt; 100)


return 0;


else


return getInputVar;

C++ coding problem?
I am not positive what you are trying to do, are you asking how to let the "return getInputVar;" return to userInput? If so, there's a simple way to do it. Remember that you want the return value to return to something (i.e. using a =...). Hopefully that's enough of a hint.
Reply:1) how is the function "getinput()" declared? Is it declared with a return value, or no return value? example: int getinput() return value, getinput() no return value.





2) how is getinputVar declared in the arguments list for getinput() function? is it "int getinputVar" or "int* getinputVar"?





3)userinput is never assigned a value before being passed to the getinput() function (just poor programming practice, unless it is a pointer to userinput).
Reply:Can you access userInput from the getInput function you've wrote? Try adding userInput = getInputVar; just after the else and before the return statement at the end, and see if it lets you compile. The reason the program outputs random numbers for userInput right now is because you've declared the variable but haven't assigned any value to it yet, so the value stored at that spot in memory is just whatever happened to be stored there last time that memory spot was used by some program. This is called a garbage value because it means absolutely nothing to you or your program.
Reply:u can use main function to call that function and return its value in a variable as::








main()


{





var = fun( parameter list );





}





return type fun( parameter list );


{





return( what u want );


}





var and return type of function should be compatible


Where i can library management software or in this c program...?

Try these:


Hot do I convert Windows C++ to Mac C++?

I am trying to convert the final C++ project that I coded on my Windows to my Mac. I don't know if windows use different libraries but the build doesn't seem to work on my Mac. If it makes any difference I am using Virtual C++ Express Edition on my Windows and XCode on my Mac.

Hot do I convert Windows C++ to Mac C++?
If I'm not mistaken, Mac and Windows are not compatible as they use a different (binary) platform.





I imagine that you'll have to rewrite the Windows C++ to a Mac compatible platform.





It shouldn't be too hard, as I'm sure most routines are similar and then just do the debugging.





Good luck.


;-)


Can you include C++ source files in other ones?

C++ is really confusing me. I'm working on a project with a lot of files: source codes, header files, libraries. It is a jungle with tons of files, classes and structures that must be defined somewhere. I'm new to C++





What type of comunication can exist between C++ files? Can you declare classes or objects in one file and use it in another one? Or is it best to use functions? And can you call a function in one file from another?

Can you include C++ source files in other ones?
You define your function prototypes and/or class definitions in the header files and then implement them in the source files. The compiler is run against each source file and the included headers for each source file are copied into the source file. Then the compiler creates object/compiled code for the source file and spits out an object file. If another source file also includes the header file with functions implemented in another object file, the linker is provided with this information so that the external symbols can be resolved during linking. When you use an IDE such as Visual C++ this tedious stuff normally seen in a make file is all handled for you.





Basically just remember to put the definitions in the headers and implementation in source.





Example:





---------------------Stack.h----------...


#ifndef __STACK__


#define __STACK__





struct StackData


{


char Data;


StackData *Node;


};





class Stack


{


private:


StackData* m_Head;





public:


Stack();


virtual ~Stack();


void Push(char Data);


char Pop( void );


bool IsEmpty( void );


};





#endif





---------------------Stack.cpp--------...





#include "Stack.h"





#ifndef NULL


#define NULL 0


#endif








Stack::Stack(): m_Head(NULL) { /* Constructor */ }





// Destructor


Stack::~Stack()


{


while(m_Head != NULL)


{


StackData *OldNode = m_Head;


m_Head = m_Head-%26gt;Node;





delete OldNode;


}


}





void Stack::Push(char Data)


{


StackData *NewData = new StackData();





NewData-%26gt;Data = Data;


NewData-%26gt;Node = NULL;





if (m_Head == NULL)


{


m_Head = NewData;


}


else


{


NewData-%26gt;Node = m_Head;


m_Head = NewData;


}


}





char Stack::Pop( void )


{


char Result = '\0';





if(m_Head != NULL)


{


Result = m_Head-%26gt;Data;





StackData *OldData = m_Head;


m_Head = m_Head-%26gt;Node;


delete OldData;


}





return Result;





}





bool Stack::IsEmpty( void )


{


return (m_Head == NULL);


}





---------------------main.cpp---------...





#include %26lt;iostream%26gt;


#include %26lt;string%26gt;


#include %26lt;string.h%26gt;


#include "Stack.h"





using namespace std;





void main( void )


{


string sInput;


string sOutput;


Stack oStack;





cout %26lt;%26lt; "Enter a string: " %26lt;%26lt; endl;


cin %26gt;%26gt; sInput;





for( size_t i = 0; i %26lt; sInput.length(); i++)


oStack.Push(sInput[i]);





while(!oStack.IsEmpty())


sOutput += oStack.Pop();





if (sInput.compare(sOutput) == 0)


cout %26lt;%26lt; "It is a palindrome." %26lt;%26lt; endl;


else


cout %26lt;%26lt; "It is NOT a palindrome." %26lt;%26lt; endl;


}
Reply:You can #include "filename.cpp" to obtain a class(es)/functions, but I consider it poor programming. Typically you want to include only the header and link additional source file.
Reply:#include %26lt;file path%26gt;

quince