I was able to build and link to a DLL using the steps here but a console application using DevC++:I haven't built a DLL before, I'll try following the guide and see what happens though.
I was able to build and link to a DLL using the steps here but a console application using DevC++:
http://msdn.microsoft.com/en-us/library/ms235636(v=VS.90).aspx
How big is your project? Are you able to post your code?
#ifndef _DLL_H_
#define _DLL_H_
#if BUILDING_DLL
# define DLLIMPORT __declspec (dllexport)
#else /* Not BUILDING_DLL */
# define DLLIMPORT __declspec (dllimport)
#endif /* Not BUILDING_DLL */
// MathFuncsDll.h
namespace MathFuncs
{
class DLLIMPORT MyMathFuncs
{
public:
// Returns a + b
double Add(double a, double b);
// Returns a - b
double Subtract(double a, double b);
// Returns a * b
double Multiply(double a, double b);
// Returns a / b
// Throws DivideByZeroException if b is 0
double Divide(double a, double b);
};
}
#endif /* _DLL_H_ */
// MathFuncsDll.cpp
#include "MathFuncsDll.h"
#include <stdexcept>
using namespace std;
namespace MathFuncs
{
double MyMathFuncs::Add(double a, double b)
{
return a + b;
}
double MyMathFuncs::Subtract(double a, double b)
{
return a - b;
}
double MyMathFuncs::Multiply(double a, double b)
{
return a * b;
}
double MyMathFuncs::Divide(double a, double b)
{
if (b == 0)
{
throw new invalid_argument("b cannot be zero!");
}
return a / b;
}
}
// MyExecRefsDll.cpp
#include <iostream>
#include "MathFuncsDll.h"
using namespace std;
int main()
{
MathFuncs::MyMathFuncs *mathInstance = new MathFuncs::MyMathFuncs();
double a = 7.4;
int b = 99;
cout << "a + b = " <<
mathInstance->Add(a, b) << endl;
cout << "a - b = " <<
mathInstance->Subtract(a, b) << endl;
cout << "a * b = " <<
mathInstance->Multiply(a, b) << endl;
cout << "a / b = " <<
mathInstance->Divide(a, b) << endl;
delete mathInstance;
system("PAUSE");
return EXIT_SUCCESS;
}
*snip*
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct valDatFor
{
public:
double num;
char ch2;
double average;
};
const int fortySix = 46;
void getFileName(ifstream& inFile)
{
cout << "Enter the location of the '.txt' file to be opened:";
char filename[301];
cin.getline(filename, 300);
inFile.open(filename);
if(inFile.fail() )
exit(0);
}
void countWords(ifstream& file)
{
int words = 0;
const char space = ' ';
const char tab = '\t';
const char nully = '\0';
string real;
do
{
file >> real;
if (space || tab || nully)
words++;
}
while(!file.eof() );
cout << "There are " << words << " words in this file\n";
file.clear();
file.seekg(0, std::ios::beg); // Moves to begining of file
cout << "Pass return to BoF\n";
}
void countChars(ifstream& file, valDatFor lett_punc_symb[fortySix])
{
char ch;
int chCounter = 0;
for(int i = 0; i < fortySix; i++)
{
lett_punc_symb[i].num = 0;
}
lett_punc_symb[0].ch2 = 'a';
lett_punc_symb[1].ch2 = 'b';
lett_punc_symb[2].ch2 = 'c';
lett_punc_symb[3].ch2 = 'd';
lett_punc_symb[4].ch2 = 'e';
lett_punc_symb[5].ch2 = 'f';
lett_punc_symb[6].ch2 = 'g';
lett_punc_symb[7].ch2 = 'h';
lett_punc_symb[8].ch2 = 'i';
lett_punc_symb[9].ch2 = 'j';
lett_punc_symb[10].ch2 = 'k';
lett_punc_symb[11].ch2 = 'l';
lett_punc_symb[12].ch2 = 'm';
lett_punc_symb[13].ch2 = 'n';
lett_punc_symb[14].ch2 = 'o';
lett_punc_symb[15].ch2 = 'p';
lett_punc_symb[16].ch2 = 'q';
lett_punc_symb[17].ch2 = 'r';
lett_punc_symb[18].ch2 = 's';
lett_punc_symb[19].ch2 = 't';
lett_punc_symb[20].ch2 = 'u';
lett_punc_symb[21].ch2 = 'v';
lett_punc_symb[22].ch2 = 'w';
lett_punc_symb[23].ch2 = 'x';
lett_punc_symb[24].ch2 = 'y';
lett_punc_symb[25].ch2 = 'z';
lett_punc_symb[26].ch2 = '!';
lett_punc_symb[27].ch2 = '?';
lett_punc_symb[28].ch2 = ',';
lett_punc_symb[29].ch2 = '.';
lett_punc_symb[30].ch2 = ':';
lett_punc_symb[31].ch2 = ';';
lett_punc_symb[32].ch2 = '\'';
lett_punc_symb[33].ch2 = '\"';
lett_punc_symb[34].ch2 = '@';
lett_punc_symb[35].ch2 = '#';
lett_punc_symb[36].ch2 = '$';
lett_punc_symb[37].ch2 = '%';
lett_punc_symb[38].ch2 = '&';
lett_punc_symb[39].ch2 = '*';
lett_punc_symb[40].ch2 = '(';
lett_punc_symb[41].ch2 = ')';
lett_punc_symb[42].ch2 = '+';
lett_punc_symb[43].ch2 = '=';
lett_punc_symb[44].ch2 = '/';
lett_punc_symb[45].ch2 = '-';
lett_punc_symb[46].num = 0;
lett_punc_symb[46].ch2 = '~';
cout << "Pass struct assignment\n";
do
{
file >> ch;
switch(ch)
{
case 'a':
case 'A':
lett_punc_symb[0].num++;
break;
case 'b':
case 'B':
lett_punc_symb[1].num++;
break;
case 'c':
case 'C':
lett_punc_symb[2].num++;
break;
case 'd':
case 'D':
lett_punc_symb[3].num++;
break;
case 'e':
case 'E':
lett_punc_symb[4].num++;
break;
case 'f':
case 'F':
lett_punc_symb[5].num++;
break;
case 'g':
case 'G':
lett_punc_symb[6].num++;
break;
case 'h':
case 'H':
lett_punc_symb[7].num++;
break;
case 'i':
case 'I':
lett_punc_symb[8].num++;
break;
case 'j':
case 'J':
lett_punc_symb[9].num++;
break;
case 'k':
case 'K':
lett_punc_symb[10].num++;
break;
case 'l':
case 'L':
lett_punc_symb[11].num++;
break;
case 'm':
case 'M':
lett_punc_symb[12].num++;
break;
case 'n':
case 'N':
lett_punc_symb[13].num++;
break;
case 'o':
case 'O':
lett_punc_symb[14].num++;
break;
case 'p':
case 'P':
lett_punc_symb[15].num++;
break;
case 'q':
case 'Q':
lett_punc_symb[16].num++;
break;
case 'r':
case 'R':
lett_punc_symb[17].num++;
break;
case 's':
case 'S':
lett_punc_symb[18].num++;
break;
case 't':
case 'T':
lett_punc_symb[19].num++;
break;
case 'u':
case 'U':
lett_punc_symb[20].num++;
break;
case 'v':
case 'V':
lett_punc_symb[21].num++;
break;
case 'w':
case 'W':
lett_punc_symb[22].num++;
break;
case 'x':
case 'X':
lett_punc_symb[23].num++;
break;
case 'y':
case 'Y':
lett_punc_symb[24].num++;
break;
case 'z':
case 'Z':
lett_punc_symb[25].num++;
break;
case '!':
lett_punc_symb[26].num++;
break;
case '?':
lett_punc_symb[27].num++;
break;
case ',':
lett_punc_symb[28].num++;
break;
case '.':
lett_punc_symb[29].num++;
break;
case ':':
lett_punc_symb[30].num++;
break;
case ';':
lett_punc_symb[31].num++;
break;
case '\'':
lett_punc_symb[32].num++;
break;
case '\"':
lett_punc_symb[33].num++;
break;
case '@':
lett_punc_symb[34].num++;
break;
case '#':
lett_punc_symb[35].num++;
break;
case '$':
lett_punc_symb[36].num++;
break;
case '%':
lett_punc_symb[37].num++;
break;
case '&':
lett_punc_symb[38].num++;
break;
case '*':
lett_punc_symb[39].num++;
break;
case '(':
lett_punc_symb[40].num++;
break;
case ')':
lett_punc_symb[41].num++;
break;
case '+':
lett_punc_symb[42].num++;
break;
case '=':
lett_punc_symb[43].num++;
break;
case '/':
lett_punc_symb[44].num++;
break;
case '-':
lett_punc_symb[45].num++;
break;
default:
break;
}
}
while(!file.eof() );
cout << "Pass switch\n";
}
void sortChars(valDatFor lett_punc_symb[fortySix])
{
int out, loc, temp;
for(out = 1; out < 45; out++)
if(lett_punc_symb[out].num < lett_punc_symb[out - 1].num)
{
temp = lett_punc_symb[out].num;
loc = out;
do
{
lett_punc_symb[loc].num = lett_punc_symb[loc - 1].num;
loc--;
}
while (loc > 0 && lett_punc_symb[loc - 1].num > temp);
lett_punc_symb[loc].num = temp;
}
}
void printCount(valDatFor lett_punc_symb[fortySix])
{
for(int i = 0; i < 46; i++)
{
lett_punc_symb[46].average += lett_punc_symb[i].num;
}
ofstream outFile;
outFile.open("C:\\Users\\Strokes\\Desktop\\Results.txt");
outFile << "Letter: Number: Percent: \n";
for(int i = 0; i < 46; i++)
{
outFile << " " << lett_punc_symb[i].ch2 << " ";
outFile << lett_punc_symb[i].num << " " << lett_punc_symb[i].num / lett_punc_symb[46].average << "%" << endl;
}
cout << "Letter: Number: Percent: \n";
for(int i = 0; i < 46; i++)
{
cout << " " << lett_punc_symb[i].ch2 << " ";
cout << lett_punc_symb[i].num << " " << lett_punc_symb[i].num / lett_punc_symb[46].average << "%" << endl;
}
}
int main()
{
ifstream file;
getFileName(file);
countWords(file);
valDatFor lett_punc_symb[fortySix];
countChars(file, lett_punc_symb);
sortChars(lett_punc_symb);
printCount(lett_punc_symb);
return 0;
}
Very peculiar. My professor was saying to reference the header file with brackets like #include <bst> (perhaps thats for those magical .lib libraries.) I'll play around with it some more this weekend.
I think the cruel irony is referencing things in c++ visual studio is a joke. You have to add half a million PATH="5$.903" bull declarations to its build. Whereas C# visual studio its right click > add reference > done.
But yes, I'll try making a mini project this weekend with math functions, slowly getting it working and building up before trying to get this dll working with my main program again.
On a completely unrelated note (homework for my next class): does COFO have an assembly thread?
Maybe my topic belonged more here.
I am Computer Science major who is working in JAVA right now. Learned GUI and up to Linked List and some other stuff. Classes and whatnot.
I assume as I progress, it will be required to know C++.
This summer, I am wanting to teach myself some C++, and try and get a small grasp, or as much as I can get, before I transfer this coming fall.
Does anyone have any books, or tutorial pages to work off of?
As well, what good compilers would one use for C++?
I work with NetBeans in JAVA.
#include <iostream.h>
// main: generate some simple output
void main ()
{
cout << "Hello, world." << endl;
return 0
}
#include <iostream>
// main: generate some simple output
void main ()
{
cout << "Hello, world." << endl;
return 0
}
can someone help me fix this, so that I can actually have achieved something today?"ComeauTest.c", line 3: error: return type of function "main" must be "int"
So use int main() OR int main(int argc, char *argv[])
void main ()
^
"ComeauTest.c", line 5: error: identifier "cout" is undefined,
Perhaps use "std::cout", or "using namespace std;"?
Did you #include <iostream>?"
cout << "Hello, world." << endl;
^
"ComeauTest.c", line 5: error: identifier "endl" is undefined,
Perhaps use "std::endl", or "using namespace std;"?
Did you #include <iostream>?"
cout << "Hello, world." << endl;
^
"ComeauTest.c", line 6: error: return value type does not match the function type
return 0
^
"ComeauTest.c", line 7: error: expected a ";" (perhaps on the previous statement)
}
^cout << "Hello, world." << endl;
return 0
}
Ok. Getting a little confused here. Working in simple C++. Trying to use a online compiler to convert the simple program "hello world", but I am getting a bunch of errors with it.
The compiler I am using right now (at school) is http://www.comeaucomputing.com/tryitout/.
The original program code is:
the first error says the <iostream.h> isn't valid, and to use <iostream>. Ok, so I corrected that toCode:#include <iostream.h> // main: generate some simple output void main () { cout << "Hello, world." << endl; return 0 }
and now I am getting an error that says can someone help me fix this, so that I can actually have achieved something today?Code:#include <iostream> // main: generate some simple output void main () { cout << "Hello, world." << endl; return 0 }
#include <iostream>
// main: generate some simple output
using namespace std; // <------- added namespace
int main () //<-----changed void to int
{
cout << "Hello, world." << endl;
return 0; //<---added semicolon
}
Newbie here. I want to learn C++, so I downloaded the Visual C++ Express 2010 from Microsoft, ordered a C++ book (http://cgi.ebay.com/ws/eBayISAPI.dl...38&ssPageName=ADME:L:OC:US:1123#ht_500wt_1202)
I just don't know where to go from here. No classes at school... not really any resources in the city I live in.