Greetings all. Been lurking for a while. Appreciate all the great stuff that's been posted!
I was looking for details on the GetVar and SetVar functions provided by GV.DLL but couldn't find much.
The forum search seems broken, and Google only returns a single post mentioning it.
Anyway, it seemed simple enough, so I just wrote my own. Below is the code ripped out of my DLL code.
It's not complete in that you'll have to add the usual wrapper code such as MSXInfo and MSXNthFunction.
The code that's been #if 0'd out is just debugging code and may be ripped out if you like. It just saves
the variable names that have been defined to a text file.
The variable names are case insensitive, so the variable longData is the same as LONGDATA.
(I think. Untested really, but it should work)
Released as freeware. Feel free to do with it what you like.
Suggestions and improvements always welcome.
[code:1:309a09b811]
typedef struct
{
char * variableName;
MSXResultRec resultRec;
} SavedVar;
typedef std::list<SavedVar *> SavedVarList;
typedef SavedVarList::iterator SavedVarListListItr;
SavedVarList savedVariablesList;
SavedVar *FindSavedVar(char *variableName)
{
if (savedVariablesList.empty())
return NULL;
SavedVar * nextSavedVar;
SavedVarListListItr listItr;
#if 0
DWORD bytesWritten;
HANDLE fileHandle = NULL;
fileHandle = CreateFile("c:\\\\FindSavedVar.txt", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if ((fileHandle != 0) && (fileHandle != INVALID_HANDLE_VALUE))
SetFilePointer(fileHandle, 0, NULL, FILE_END);
WriteFile(fileHandle, "\\n", 1, &bytesWritten, NULL);
#endif
listItr = savedVariablesList.begin();
while (listItr != savedVariablesList.end())
{
nextSavedVar = *listItr;
#if 0
WriteFile(fileHandle, nextSavedVar->variableName, strlen(nextSavedVar->variableName), &bytesWritten, NULL);
WriteFile(fileHandle, "\\n", 1, &bytesWritten, NULL);
#endif
if (!_stricmp(nextSavedVar->variableName, variableName))
return nextSavedVar;
++listItr;
}
return NULL;
}
BOOL __stdcall SetVar(const MSXDataRec *a_psDataRec,
const MSXDataInfoRecArgsArray *a_psDataInfoArgs,
const MSXNumericArgsArray *a_psNumericArgs,
const MSXStringArgsArray *a_psStringArgs,
const MSXCustomArgsArray *a_psCustomArgs,
MSXResultRec *a_psResultRec)
{
int dataIndex;
SavedVar * savedVar;
// Set up return variables to default to error condition.
a_psResultRec->psResultArray->iFirstValid = 0;
a_psResultRec->psResultArray->iLastValid = -1;
if (a_psDataInfoArgs->iNRecs != 1)
{
strncpy_s(a_psResultRec->szExtendedError, "SetVar: Wrong number of arguments", sizeof(a_psResultRec->szExtendedError) - 1);
return MSX_ERROR;
}
if (a_psStringArgs->iNRecs != 1)
{
strncpy_s(a_psResultRec->szExtendedError, "SetVar: Wrong number of arguments", sizeof(a_psResultRec->szExtendedError) - 1);
return MSX_ERROR;
}
savedVar = FindSavedVar(a_psStringArgs->pszStrings[0]);
if (savedVar == NULL)
{
// New variable. Create it.
savedVar = new SavedVar;
savedVar->variableName = new char[strlen(a_psStringArgs->pszStrings[0]) + 10];
strcpy_s(savedVar->variableName, strlen(a_psStringArgs->pszStrings[0]) + 1, a_psStringArgs->pszStrings[0]);
savedVar->resultRec.psResultArray = new MSXDataInfoRec;
savedVar->resultRec.psResultArray->pfValue = new float[65500]; // save room for max size
savedVariablesList.push_back(savedVar);
}
savedVar->resultRec.psResultArray->iFirstValid = a_psDataInfoArgs->psDataInfoRecs[0]->iFirstValid;
savedVar->resultRec.psResultArray->iLastValid = a_psDataInfoArgs->psDataInfoRecs[0]->iLastValid;
for (dataIndex = a_psDataInfoArgs->psDataInfoRecs[0]->iFirstValid; dataIndex <= a_psDataInfoArgs->psDataInfoRecs[0]->iLastValid; dataIndex++)
savedVar->resultRec.psResultArray->pfValue[dataIndex] = a_psDataInfoArgs->psDataInfoRecs[0]->pfValue[dataIndex];
return MSX_SUCCESS;
}
BOOL __stdcall GetVar(const MSXDataRec *a_psDataRec,
const MSXDataInfoRecArgsArray *a_psDataInfoArgs,
const MSXNumericArgsArray *a_psNumericArgs,
const MSXStringArgsArray *a_psStringArgs,
const MSXCustomArgsArray *a_psCustomArgs,
MSXResultRec *a_psResultRec)
{
int dataIndex;
SavedVar * savedVar;
// Set up return variables to default to error condition.
a_psResultRec->psResultArray->iFirstValid = 0;
a_psResultRec->psResultArray->iLastValid = -1;
if (a_psStringArgs->iNRecs != 1)
{
strcpy_s(a_psResultRec->szExtendedError, MSX_MAXSTRING - 1, "GetVar: Wrong number of arguments");
return MSX_ERROR;
}
savedVar = FindSavedVar(a_psStringArgs->pszStrings[0]);
if (savedVar == NULL)
{
sprintf_s(a_psResultRec->szExtendedError, MSX_MAXSTRING - 1, "GetVar: Variable '%s' not found", a_psStringArgs->pszStrings[0]);
return MSX_ERROR;
}
for (dataIndex = savedVar->resultRec.psResultArray->iFirstValid; dataIndex <= savedVar->resultRec.psResultArray->iLastValid; dataIndex++)
a_psResultRec->psResultArray->pfValue[dataIndex] = savedVar->resultRec.psResultArray->pfValue[dataIndex];
a_psResultRec->psResultArray->iFirstValid = savedVar->resultRec.psResultArray->iFirstValid;
a_psResultRec->psResultArray->iLastValid = savedVar->resultRec.psResultArray->iLastValid;
return MSX_SUCCESS;
}
[/code:1:309a09b811]