I am getting the following error: I am using vs2008 and e-mail.h is included in the project

Error 1 error LNK2028: unresolved token (0A00004A) "public: void __thiscall MyEmail::Createfile(void)" (?Createfile@MyEmail@@$$FQAEXXZ) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ) test.obj e-mail

Error 2 error LNK2019: unresolved external symbol "public: void __thiscall MyEmail::Createfile(void)" (?Createfile@MyEmail@@$$FQAEXXZ) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ) test.obj e-mail


Error 3 fatal error LNK1120: 2 unresolved externals C:\Documents and Settings\jmartinez\My Documents\Visual Studio 2008\Projects\e-mail\Debug\e-mail.dll e-mail

#include "stdafx.h"
#include "e-mail.h"

void main ()
{
	MyEmail e;

	e.Createfile();

}

You have the .h file but you failed to add the c++ code for that email class. If its some library you are using then you have to add the *.lib to the project.

I created the class and I added another file called test. I want to use this to test it. I created it inside the same project.

I have email.h in "header files" and email.cpp in "source files" where do i add *.lib to the project.

Just curious, but what are the contents e-mail.h and e-mail.cpp? (Abbreviate it if it's a bit long.) You don't need *.lib files because you're not using an external library.

If you have the source code then there be no *.lib, so don't worry about it. Please post all the code for your project, that is, all the *.cpp files and *.h files you created. And the Solution Explorer should show all those files.

#include <comdef.h>
#include <iostream>
#include <fstream>
#include "aosmtp.tlh"
#include <string>
#include < sys/stat.h>
#include < io.h>

using namespace System;
using namespace std;
using namespace AOSMTPLib;
using namespace std;

const string file = "c:\\email.txt";

void Createfile()
{	
	ofstream fout;
	ifstream fin;
	
	
	string pound = "######################################################";

	fout.open("file");

	fout << pound << "\n" << "from: 	Type email address here" << pound << "\n";
	fout << pound << "\n" << "To:	Type in Recipient e-mail here" << pound << "\n";
	fout << pound << "\n" << "Subject:	Type subject here" << pound << "\n";
	fout << pound << "\n" << "Body:	Start writing body here" << pound << "\n";

	fout.close();


}
#include "aosmtp.tlh"

class MyEmail
{
public:
	

	void Createfile();

};

line 15: void Createfile() You forgot the class scope operator, so the compiler is treating it as a simple function that is not associated with any class.

Correct: void MyEmail::Createfile() >>without the test file it compiles fine
Certainly -- because there is nothing that actually uses the MyEmail class.

// e-mail.h
#include "aosmtp.tlh"

class MyEmail
{
public:
	
	//void SendEmail();

	void MyEmail::Createfile();

};

I get the same error.

>but do I need to do it that way even though I have the namespace included??
That's not a namespace. It's a way of specifying which class your function definition is meant for.

// e-mail.h
#include "aosmtp.tlh"

class MyEmail
{
public:
	
	//void SendEmail();

	void MyEmail::Createfile();

};

I get the same error.

No, don't change the .h file. It's the .cpp file you need to change:

void myEmail::Createfile()
{
.
.
.
}
This article has been dead for over six months. Start a new discussion instead.