Storing Variables in RUNDATA
Ever since I started writing extensions, I've always stored variables by declaring them at the top of Main.cpp. This has always sufficed my needs, but from what I hear it seems that doing this is considered unethical or sloppy. It also has the disadvantage of not being universal to the extension, a characteristic which I need for my current project.
So I was wondering how to store variables in the RUNDATA structure (if that's what it's called). I can store integers in it with no imminent trouble, and probably some other datatypes. But a lot of times when I try to store something, I get errors asking for semicolons and type specifiers. I, of course, have these, which is what confuses me.
Specifically, what I'm trying to do is store a vector of structures. But when I try to store a vector of any type, I get the errors I mentioned above. I also find that I don't know where to define the structures I need for the vector.
So the question is: How do I store most variables in RUNDATA (specifically vectors), and where can I define a structure that the vector will store?
Any help would be much appreciated. :)
Thanks,
Jaffob
Re: Storing Variables in RUNDATA
Store a pointer to it and (de)allocate it in Runtime.cpp, done ;)
Re: Storing Variables in RUNDATA
You're wanting something like this:
Code:
struct VectorStoresThis
{
INT crazycrap;
};
#include <vector>
typedef struct tagRDATA
{
vector<VectorStoresThis>* pVector;
} RUNDATA;
Then in Runtime.cpp:
Code:
short WINAPI DLLExport CreateRunObject(LPRDATA rdPtr, LPEDATA edPtr, fpcob cobPtr)
{
rdPtr->pVector = new vector<VectorStoresThis>;
// No errors
return 0;
}
short WINAPI DLLExport DestroyRunObject(LPRDATA rdPtr, long fast)
{
delete rdPtr->pVector;
// No errors
return 0;
}
Re: Storing Variables in RUNDATA
That works for storing variables and accessing them, although defining a structure doesn't seem to work. Using Dynasoft's code, I get the same errors as I was getting before — but now for individual elements within the structures. I have them defined at the top of Data.h, right below the following code:
Code:
class rRundata;
typedef rRundata * LPRRDATA;
Any idea how to fix this?
Thanks again. :)
Re: Storing Variables in RUNDATA
It would be very helpful if you would post the exact error you're getting, and the exact line of code (preferably, block of code) that is producing that error.
Re: Storing Variables in RUNDATA
Well I've gotten rid of a few of the errors, but I still get a fair number of other ones. Here's the top part of my Data.h:
Code:
class rRundata;
typedef rRundata * LPRRDATA;
struct MYSUBMENUOBJ {
char * name;
HMENU handle;
} ;
struct MYMENUOBJ {
char * name;
HMENU handle;
vector <MYSUBMENUOBJ> submenus;
RECT excrect;
} ;
#include <vector>
// --------------------------------
// RUNNING OBJECT DATA STRUCTURE
// --------------------------------
// If you want to store anything between actions/conditions/expressions
// you should store it here
typedef struct tagRDATA
{
#include "MagicRDATA.h"
vector <MYMENUOBJ> * menuList;
unsigned int lastError = 0;
} RUNDATA;
typedef RUNDATA * LPRDATA;
The following errors occur on the line where the "submenus" vector is declared in MYMENUOBJ:
Code:
error C2143: syntax error : missing ';' before '<'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2238: unexpected token(s) preceding ';'
I guess it's also a vector, so it has the same problem as vectors in RUNDATA do. I also just realized that the errors with declaring variables were not in fact solved. I get the following errors on the vector in RUNDATA:
Code:
error C2143: syntax error : missing ';' before '*'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
And this for the integer:
Code:
error C2864: 'tagRDATA::lastError' : only static const integral data members can be initialized within a class
Thanks again. :)
Re: Storing Variables in RUNDATA
It has to be std::vector... unless you specify "using namespace std;" after including the header.
Plus, you can't define variables in struct definitions! You should do it in CreateRunObject. rdPtr->lastError = 0;
Re: Storing Variables in RUNDATA
#include <vector> must come before you first use the vector. Put it above the second struct definition.
Re: Storing Variables in RUNDATA
Okay, last night I finally got it working. It took me a little while to realize that I would need to use (*rdPtr->menuList) to actually do stuff with the vector (first I forgot it was a pointer :blush:, and then I realized it needed parentheses as well). But it all compiles flawlessly now. :grin:
Many thanks to the three of you. :)
Re: Storing Variables in RUNDATA
You actually don't, unless you want to use the [] operator.
You can still use rdPtr->menuList->at(X), ->insert(...) etc.