XP toolkit: using SetVar()
- I'm writing a couple of extremely simple XP commands, each of
which sets a CC2 variable to "1" or "0" depending upon whether
or not an entity is of a certain type (e.g. a line). Each
command takes the variable name as its first input, and the
entity to check as its second. What the code does is simply
determine whether or not a "1" or "0" should be used as the CC2
variable's value, and then it uses the XP toolkit library func-
tion SetVar() to set the variable accordingly.
Unfortunately, SetVar() seems to be causing problems. I'm
passing it two arrays of chars, the first holding the variable
name, and the second holding the variable value. Both arrays
are globally-scoped, not local. The command executes success-
fully, and I can retrieve the value of the CC2 variable using
MSGBOX to check it. But at a seemingly random point later on,
CC2 crashes, which tells me that something I'm doing is munging
memory. Is there anything about SetVar() that I need to know
in order to use it properly? I admit that it's been a few
months since I've done any XP work, and I may be a bit rusty...
Thanks in advance,
- From your description I think you are ok with SetVar. I even use it with
const strings, like:
You can have local variables as well. Are sure there isn't anything else
that causes the problem?
To return true or false to a macro you can also set the IFERR flag:
DWORD * XPCALL GetErrFlagAdr(void);
// Set flag true
*pMacroErrFlag = TRUE;
- Peter Olsson wrote:
> From your description I think you are ok with SetVar. I even use it withI came back to it fresh, and after a bit realized what I had
> const strings, like:
> SetVar("FKOLL", "10");
> You can have local variables as well. Are sure there isn't anything else
> that causes the problem?
done wrong. SetVar() was just fine, as you said; the problem
was that when I asked the user for a variable name, I was for-
getting to specify the RDF_NOVARX flag in the RDATA structure.
Thus, when I used SetVar() to set the variable name "foo", and
then ran my command a second time and used "foo" again, the
second time "foo" would arrive as "0" or "1" (the value it had
been assigned the first time around). Thus I'd use SetVar()
on the variable "0", which causd CC2 to eventually crash.
I have never written an XP that requires the user to input a
variable name before, and thus hadn't thought of this issue.
My mistake. Now that I've fixed this, things seem to be work-
Thanks for your help, as always!