![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Expert Programmer
|
Please Fix My Dll
Class declaration in header:
#include <vector>
#include <stdlib.h>
class __declspec(dllexport) Engine
{
public:
Engine();
~Engine();
// Booleans stating wether or not
// the function is included in the
// script
//////////////////////////////////
bool b_mailFile;
bool b_xFile;
bool b_samFile;
bool b_upload;
//////////////////////////////////
// exclusive MailFile Function
// variables
//////////////////////////////////
bool b_promptDataFile;
// booleans telling us wether or
// not specific criteria is located
// within the script or not
bool b_dataFile;
bool b_inputType;
bool b_outputType;
bool b_delimiter;
bool b_preset;
bool b_numUp;
bool b_spoolSize;
// if the criteria is located
// we use strings to store the
// value
std::string s_dataFile;
std::string s_inputType;
std::string s_outputType;
std::string s_delimiter;
std::string s_preset;
std::string s_numUp;
std::string s_spoolSize;
//////////////////////////////////
// exclusive XFile Function
// variables
//////////////////////////////////
// booleans telling us wether or
// not specific criteria is located
// within the script or not
bool b_xInputType;
bool b_xOutputType;
bool b_xPreset;
bool b_xRotateOn;
bool b_xSort;
bool b_xSortOn;
bool b_xQuantity;
// if the criteria is located
// we use strings to store the
// value
std::string s_xInputType;
std::string s_xOutputType;
std::string s_xPreset;
std::string s_xRotateOn;
std::string s_xSort;
std::string s_xSortOn;
std::string s_xQuantity;
//////////////////////////////////
// exclusive SamFile Function
// variables
//////////////////////////////////
// booleans telling us wether or
// not specific criteria is located
// within the script or not
bool b_samRotateOn;
bool b_samSort;
bool b_samSortOn;
bool b_samQuantity;
// if the criteria is located
// we use strings to store the
// value
std::string s_samRotateOn;
std::string s_samSort;
std::string s_samSortOn;
std::string s_samQuantity;
//////////////////////////////////
// exclusive UpLoad Function
// variables
//////////////////////////////////
// booleans telling us wether or
// not specific criteria is located
// within the script or not
bool b_upAccount;
bool b_upCampaign;
bool b_upServer;
// if the criteria is located
// we use strings to store the
// value
std::string s_upAccount;
std::string s_upCampaign;
std::string s_upServer;
//////////////////////////////////
// Error Array
//////////////////////////////////
std::vector<std::string> s_errorArray;
//////////////////////////////////
// Method (PROTOTYPES)
//////////////////////////////////
std::vector<std::string> _stdcall ReturnErrors();
std::string _stdcall LTrim(std::string trimString);
std::string _stdcall Trim(std::string trimString);
bool _stdcall ParseFunctionHeaders(std::vector<std::string> script);
bool _stdcall MailFileIntegrity(std::vector<std::string> script);
bool _stdcall XFileIntegrity(std::vector<std::string> script);
bool _stdcall SamFileIntegrity(std::vector<std::string> script);
bool _stdcall UploadIntegrity(std::vector<std::string> script);
bool _stdcall ParseMailFileContents(std::vector<std::string> script);
//////////////////////////////////
private:
// exclusive MailFile Function
// variables
//////////////////////////////////
bool b_mailFileBegin;
bool b_mailFileEnd;
int i_mailFilePos;
int i_mailfuncStart;
int i_mailfuncEnd;
//////////////////////////////////
// exclusive XFile Function
// variables
//////////////////////////////////
bool b_xFileBegin;
bool b_xFileEnd;
int i_xFilePos;
int i_xfuncStart;
int i_xfuncEnd;
//////////////////////////////////
// exclusive SAMFile Function
// variables
//////////////////////////////////
bool b_samFileBegin;
bool b_samFileEnd;
int i_samFilePos;
int i_samfuncStart;
int i_samfuncEnd;
//////////////////////////////////
// exclusive UPLOAD Function
// variables
//////////////////////////////////
bool b_upFileBegin;
bool b_upFileEnd;
int i_upFilePos;
int i_upfuncStart;
int i_upfuncEnd;
//////////////////////////////////
// Methods (PROTOTYPES) (PRIVATE)
//////////////////////////////////
void _stdcall AddError(std::string error);
void _stdcall AddError(bool lineAdd, int lineNum, std::string error);
//////////////////////////////////
};functions definitions in cpp file: // Engine Contructor
Engine::Engine()
{
}
// Engine Deconstructor
Engine::~Engine()
{
}
// Adds new error to the 'errorArray' vector
void _stdcall Engine::AddError(std::string error)
{
s_errorArray.push_back(error);
}
// OVERLOADED AddError(bool,int,string)
void _stdcall Engine::AddError(bool lineAdd, int lineNum, std::string error)
{
std::string s_tempError;
s_tempError += "[LINE#";
s_tempError += (char)lineNum;
s_tempError += "] ";
s_tempError += error;
s_errorArray.push_back(s_tempError);
}
// Returns all errors generated by a poorly written script
std::vector<std::string> Engine::ReturnErrors()
{
if(s_errorArray.size() != 0)
return s_errorArray;
else
{
s_errorArray.clear();
s_errorArray.push_back("none");
return s_errorArray;
}
}
// HOMEADE LEFT TRIM FUNCTION
std::string _stdcall Engine::LTrim(std::string trimString)
{
std::string temp = trimString.c_str();
for(unsigned int i = 0; i<= sizeof(temp); i++)
{
if(temp[i] = ' ')
{
trimString = "";
for(unsigned int k = i+1; k <= sizeof(temp) - (i+1); k++)
{
trimString += temp[k];
}
}
}
return trimString;
}
// HOMEADE TRIM FUNCTION
std::string _stdcall Engine::Trim(std::string trimString)
{
std::string temp = trimString.c_str();
for(unsigned int i = 0; i <= temp.length(); i++)
{
if(temp[i] == ' ')
{
trimString = "";
for(unsigned int k = i+1; k <= temp.length() - (i+1); k++)
{
trimString += temp[k];
}
}
else
break;
}
for(size_t i = temp.length(); i >= 0; i--)
{
if(temp[i] == ' ')
{
for(unsigned int k = 0; k <= temp.length() - (i-1); k++)
{
trimString += temp[k];
}
}
else
break;
}
return trimString;
}
// PARSE HEADERS FUNCTION
bool _stdcall Engine::ParseFunctionHeaders(std::vector<std::string> script)
{
b_mailFile = false;
b_xFile = false;
b_samFile = false;
b_upload = false;
for(unsigned int i = 0; i <= script.size(); i++)
{
if(script[i].c_str() == "")
break;
else
script[i] = Trim(script[i]);
if(script[i].c_str() == "MAILFILE" && b_mailFile == false)
{
i_mailFilePos = i;
b_mailFile = true;
}
else if(script[i].c_str() == "MAILFILE" && b_mailFile == true)
{
AddError(true, (i+1), "ER1003 Multiple Instance (MAILFILE)");
}
else if(script[i].c_str() == "XFILE" && b_xFile == false)
{
i_xFilePos = i;
b_xFile = true;
}
else if(script[i].c_str() == "XFILE" && b_xFile == true)
{
AddError(true, (i+1), "ER1033 Multiple Instance (XFILE)");
}
else if(script[i].c_str() == "SAMFILE" && b_samFile == false)
{
i_samFilePos = i;
b_samFile = true;
}
else if(script[i].c_str() == "SAMFILE" && b_samFile == true)
{
AddError(true, (i+1), "ER1070 Multiple Instance (SAMFILE)");
}
else if(script[i].c_str() == "UPLOAD" && b_upload == false)
{
i_upFilePos = i;
b_upload = true;
}
else if(script[i].c_str() == "UPLOAD" && b_upload == true)
{
AddError(true, (i+1), "ER1071 Multiple Instance (UPLOAD)");
}
}
if(b_mailFile == false)
{
AddError("ER1001 Script missing required headers (MAILFILE)");
return false;
}
return true;
}
// MAILFILE integrity check
bool _stdcall Engine::MailFileIntegrity(std::vector<std::string> script)
{
b_mailFileBegin = false;
b_mailFileEnd = false;
int i_beginBracket=0;
for(unsigned int i = i_mailFilePos; i <= script.size(); i++)
{
if(script[i].c_str() == "")
break;
else
script[i] = Trim(script[i]);
if(script[i].c_str() == "{")
{
i_beginBracket = i;
i_mailfuncStart = i+1;
b_mailFileBegin = true;
break;
}
}
for(unsigned int i = i_beginBracket; i <= script.size(); i++)
{
if(script[i].c_str() == "")
break;
if(script[i].c_str() == "}")
{
i_mailfuncEnd = i-1;
b_mailFileEnd = true;
break;
}
}
if(b_mailFileBegin == false || b_mailFileEnd == false)
AddError("ER1002 Bracket Syntax Error (MAILFILE)");
return true;
}
// XFILE integrity check
bool _stdcall Engine::XFileIntegrity(std::vector<std::string> script)
{
b_xFileBegin = false;
b_xFileEnd = false;
int i_beginBracket=0;
for(unsigned int i = i_xFilePos; i <= script.size(); i++)
{
if(script[i].c_str() == "")
break;
else
script[i] = Trim(script[i]);
if(script[i].c_str() == "{")
{
i_beginBracket = i;
i_xfuncStart = i+1;
b_xFileBegin = true;
break;
}
}
for(unsigned int i = i_beginBracket; i<= script.size(); i++)
{
if(script[i].c_str() == "")
break;
if(script[i].c_str() == "}")
{
i_xfuncEnd = i-1;
b_xFileEnd = true;
break;
}
}
if(b_xFileBegin == false || b_xFileEnd == false)
AddError("ER1034 Bracket Syntax Error (XFILE)");
return true;
}
// SAMFILE integrity check
bool _stdcall Engine::SamFileIntegrity(std::vector<std::string> script)
{
b_samFileBegin = false;
b_samFileEnd = false;
int i_beginBracket=0;
for(unsigned int i = i_samFilePos; i <= script.size(); i++)
{
if(script[i].c_str() == "")
break;
else
script[i] = Trim(script[i]);
if(script[i].c_str() == "{")
{
i_beginBracket = i;
i_samfuncStart = i+1;
b_samFileBegin = true;
break;
}
}
for(unsigned int i = i_beginBracket; i<= script.size(); i++)
{
if(script[i].c_str() == "")
break;
else
script[i] = Trim(script[i]);
if(script[i].c_str() == "}")
{
i_samfuncEnd = i-1;
b_samFileEnd = true;
break;
}
}
if(b_samFileBegin == false || b_samFileEnd == false)
AddError("ER1069 Bracket Syntax Error (SAMFILE)");
return true;
}
// UPLOAD integrity check
bool _stdcall Engine::UploadIntegrity(std::vector<std::string> script)
{
b_upFileBegin = false;
b_upFileEnd = false;
int i_beginBracket=0;
for(unsigned int i = i_upFilePos; i <= script.size(); i++)
{
if(script[i].c_str() == "")
break;
else
script[i] = Trim(script[i]);
if(script[i].c_str() == "{")
{
i_beginBracket = i;
i_upfuncStart = i+1;
b_upFileBegin = true;
break;
}
}
for(unsigned int i = i_beginBracket; i<= script.size(); i++)
{
if(script[i].c_str() == "")
break;
else
script[i] = Trim(script[i]);
if(script[i].c_str() == "}")
{
i_upfuncEnd = i-1;
b_upFileEnd = true;
break;
}
}
if(b_upFileBegin == false || b_upFileEnd == false)
AddError("ER1071 Bracket Syntax Error (UPLOAD)");
return true;
}
// Parseing the MAILFILE contents
bool _stdcall Engine::ParseMailFileContents(std::vector<std::string> script)
{
std::string tempTrim = "";
std::string tempParse = "";
s_dataFile = "";
s_inputType = "";
s_outputType = "";
s_delimiter = "";
s_preset = "";
s_numUp = "";
s_spoolSize = "";
b_inputType = false;
b_outputType = false;
b_dataFile = false;
b_delimiter = false;
b_preset = false;
b_numUp = false;
b_spoolSize = false;
b_promptDataFile = false;
if(b_mailFileBegin == true && b_mailFileEnd == true)
{
for(int i = i_mailfuncStart; i<= i_mailfuncEnd; i++)
{
if(script[i].length() > 5)
{
tempTrim = Trim(script[i]);
try
{
if(tempTrim.substr(0,8).c_str() == "DATAFILE")
{
if(b_dataFile == true)
AddError(true, (i+1), "ER1026 DATAFILE - multiple instance (MAILFILE)");
else
{
if(i != i_mailfuncStart)
AddError(true, (i+1), "ER1011 DATAFILE must be on first line (MAILFILE)");
else
{
if(tempTrim.substr(9,9).c_str() == "@filename")
b_promptDataFile = true;
}
}
b_dataFile = true;
}
if(tempTrim.substr(0,5).c_str() == "INPUT")
{
if(b_inputType == true)
AddError(true, (i+1), "ER1027 INPUT - multiple instance (MAILFILE)");
else
{
try
{
if(tempTrim.substr(6,5).c_str() == "FIXED")
s_inputType = "FIXED";
else if(tempTrim.substr(6,9).c_str() == "DELIMITED")
s_inputType = "DELIMITED";
else
AddError(true, (i+1), "ER1006 INPUT type invalid (MAILFILE)");
}
catch(...)
{
AddError(true, (i+1), "] ER1007 INPUT parsing error (MAILFILE)");
}
}
b_inputType = true;
}
if(tempTrim.substr(0,6).c_str() == "OUTPUT")
{
if(b_outputType == true)
AddError(true, (i+1), "ER1028 OUTPUT - multiple instance (MAILFILE)");
else
{
try
{
if(tempTrim.substr(7,5).c_str() == "FIXED")
s_outputType = "FIXED";
else if(tempTrim.substr(7,9).c_str() == "DELIMITED")
s_outputType = "DELIMITED";
else
AddError(true, (i+1), "ER1009 OUTPUT type invalid (MAILFILE)");
}
catch(...)
{
AddError(true, (i+1), "ER1008 OUTPUT parsing error (MAILFILE)");
}
}
b_outputType = true;
}
if(tempTrim.substr(0,9).c_str() == "DELIMITER")
{
if(b_delimiter == true)
AddError(true, (i+1), "ER1029 DELIMITER - multiple instance (MAILFILE)");
else
{
try
{
if(tempTrim.substr(10,4).c_str() == "PIPE")
s_delimiter = "PIPE";
else if(tempTrim.substr(10,4).c_str() == "NONE")
s_delimiter = "NONE";
else if(tempTrim.substr(10,5).c_str() == "COMMA")
s_delimiter = "COMMA";
else
AddError(true, (i+1), "ER1014 DELIMITER type invalid (MAILFILE)");
}
catch(...)
{
AddError(true, (i+1), "ER1013 DELIMITER parsing error (MAILFILE)");
}
}
b_delimiter = true;
}
if(tempTrim.substr(0,6).c_str() == "PRESET")
{
if(b_preset == true)
AddError(true, (i+1), "ER1030 PRESET - multiple instance (MAILFILE)");
else
{
try
{
if(tempTrim.substr(7,4).c_str() == "NONE")
s_preset = "NONE";
else if(tempTrim.substr(7,1).c_str() == "\"" && tempTrim.substr(tempTrim.length()-1,1).c_str() == "\"")
s_preset = tempTrim.substr(8,tempTrim.length()-9);
else
AddError(true, (i+1), "ER1016 PRESET type invalid (MAILFILE)");
}
catch(...)
{
AddError(true, (i+1), "ER1017 PRESET parsing error (MAILFILE)");
}
}
b_preset = true;
}
if(tempTrim.substr(0,8).c_str() == "NUMBERUP")
{
int tempInt = 0;
if(b_numUp == true)
AddError(true, (i+1), "ER1031 NUMBERUP - multiple instance (MAILFILE)");
else
{
try
{
tempParse = tempTrim.substr(9, tempTrim.length()-9);
if(tempTrim.substr(9,1).c_str() != "")
{
s_numUp = Trim(s_numUp.substr(9,tempTrim.length()-9));
if(s_numUp.c_str() == "0")
AddError(true, (i+1), "ER1019 NUMBERUP value invalid (MAILFILE)");
}
else
AddError(true, (i+1), "ER1019 NUMBERUP value invalid (MAILFILE)");
}
catch(...)
{
AddError(true, (i+1), "ER1020 NUMBERUP parsing error (MAILFILE)");
}
}
b_numUp = true;
}
if(tempTrim.substr(0,9).c_str() == "SPOOLSIZE")
{
if(b_spoolSize == true)
AddError(true, (i+1), "ER1032 SPOOLSIZE - multiple instance (MAILFILE)");
else
{
try
{
tempParse = tempTrim.substr(10, tempTrim.length()-10);
if(tempTrim.substr(10,1).c_str() != "")
{
s_spoolSize = Trim(s_spoolSize.substr(10,s_spoolSize.length()-10));
if(s_spoolSize.c_str() == "0")
AddError(true, (i+1), "ER1023 SPOOLSIZE value invalid (MAILFILE)");
}
else
AddError(true, (i+1), "ER1023 SPOOLSIZE value invalid (MAILFILE)");
}
catch(...)
{
AddError(true, (i+1), "ER1024 SPOOLSIZE parsing error (MAILFILE)");
}
}
b_spoolSize = true;
}
}
catch(...)
{
AddError(true, (i+1), "ER1022 Keyword parsing error (MAILFILE)");
}
}
}
}
else
AddError("ER1004 Contents Integrity Failed (MAILFILE)");
if(b_inputType == false)
AddError("ER1005 INPUT type missing (MAILFILE)");
if(b_outputType == false)
AddError("ER1010 OUTPUT type missing (MAILFILE)");
if(b_dataFile == false)
AddError("ER1012 DATAFILE definition missing (MAILFILE)");
if(b_delimiter == false)
AddError("ER1015 DELIMITER type missing (MAILFILE)");
if(b_preset == false)
AddError("ER1018 PRESET definition missing (MAILFILE)");
if(b_numUp == false)
AddError("ER1021 NUMBERUP definition missing (MAILFILE)");
if(b_spoolSize == false)
AddError("ER1025 SPOOLSIZE definition missing (MAILFILE)");
return true;
}For some reason i can't use this DLL in other projects... im not sure what the heck is going on. I have made dll's in cpp before none of this is making sense to me... Anyone see anything i could add/remove?
__________________
"When in Rome, Do as the Romans Do" "Beauty is in the eye of the BEER holder" "Save your breath your going to need it for your blow up doll later" SearchLores.org |
|
|
|
|
|
#2 | |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 770
Rep Power: 3
![]() |
Having never made a DLL before, I probably can't help, but I glanced at your code and noticed this:
Quote:
|
|
|
|
|
|
|
#3 | |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Well it compiles but my compiler gives many warnings such as these:
Quote:
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
|
#4 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
You should probably read this if you haven't done so yet.
What I don't understand in your code are things like: // HOMEADE LEFT TRIM FUNCTION
std::string _stdcall Engine::LTrim(std::string trimString)
{
std::string temp = trimString.c_str();if(tempTrim.substr(0,8).c_str() == "NUMBERUP") ![]()
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
#5 | ||
|
Programmer
Join Date: Jun 2005
Posts: 99
Rep Power: 4
![]() |
Quote:
Using __declspec(dllexport) to export a class limits the importing of the DLL to compile time only (as a library/static linked DLL). This means that you will not be able to use it in a managed project as all references are resolved at run-time. The common approach, if you want to load at run-time, is to define an interface for the class and have an exported GetInstance(); function from the DLL. This way you can do a normal 'C' export and the dll can be loaded at run-time or compile-time. Quote:
|
||
|
|
|
|
|
#6 | |
|
Expert Programmer
|
Quote:
__________________
"When in Rome, Do as the Romans Do" "Beauty is in the eye of the BEER holder" "Save your breath your going to need it for your blow up doll later" SearchLores.org |
|
|
|
|
|
|
#7 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
I think what he means is you're downgrading to C strings when there's no necessity, and also when it won't work.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#8 | ||
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Quote:
Quote:
In the other example you declare a C++ string, but you don't assign it from another C++ string but from a C string ![]()
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
||
|
|
|
|
|
#9 |
|
Expert Programmer
|
without the .c_str() it bombs out for using the == operator
__________________
"When in Rome, Do as the Romans Do" "Beauty is in the eye of the BEER holder" "Save your breath your going to need it for your blow up doll later" SearchLores.org |
|
|
|
|
|
#10 | |
|
Professional Programmer
|
Well then use strcmp()...
__________________
▄▄▄▄ Quote:
Due to incorrect calculations during the middle ages, our calendar actually begins a few years after Jesus' birth. Thus the real 6/6/6 happened a few years back. The world already ended and you missed it. Download Code::Blocks now! ▄▄▄▄ |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|