2 bars source
Posted: February 10th, 2007, 4:44 pm
2 Bars c++ source, in case anyone finds it useful. I'm a relatively new programmer, so if anyone has suggestions to make this run more efficiently, they are appreciated.
Functions 1-8 just call another function using the appropriate custom character number. Ex.:
The function that does the work:
Also, a question for visual studio people (I have coded only under linux prior to this). I can build the dll just fine when I am set to debug and it works in smartie, but if I change to the release build, the dll produces garbage on the screen when called by smartie (although the file is much smaller). What is the difference between the release and debug builds and why won't the release build work?
Functions 1-8 just call another function using the appropriate custom character number. Ex.:
Code: Select all
extern "C" DLLEXPORT char *
__stdcall function1(char *param1, char *param2)
{
return bar(1, param1, param2);
}
Code: Select all
char* bar (int no, char* param1, char* param2)
{
//param1 is the value of bar 1, param2 is bar2
double vala = atof (param1);
double valb = atof (param2);
//start with a blank custom character
int graph[] = {0,0,0,0,0,0,0,0};
//and also define the $Chr numbers
static const char* const chrs[] = {"176", "158", "131", "132", "133", "134", "135", "136"};
//define the breakpoints for each pixel
static const double breaks[] = {88.89, 77.78, 66.67, 55.56, 44.44, 33.33, 22.22, 11.11};
//define the custom character
for (int i = 0; i<8; i++)
{
if (vala >= breaks[i]) graph[i] += 24;
if (valb >= breaks[i]) graph[i] += 3;
}
//build the string to return
std::stringstream ret;
ret << "$CustomChar(" << no << ",";
for (int i = 0; i < 7; i++)
ret << graph[i] << ", ";
ret << graph[7] << ")$Chr(" << chrs[no-1] << ")";
static char out[100];
strcpy(out, ret.str().c_str());
return(out);
}