Hello, tbdev.
I've written a small helper "wrapper" on С++ to be used with ITBPDataProvider
interface. Here is the source:
// tbwraper.h: interface for the wrapper of ITBPDataProvider
//
//
#if !defined(tbwraper_h)
#define tbwraper_h
#include "tbptest.h"
#include
// wrapper for the values of interface
class tbvalue
{
protected:
ITBPDataProvider* parent;
int index;
public:
tbvalue(ITBPDataProvider* c, int indx) : parent (c), index(indx) {};
void operator= (int c);
void operator= (const std::string& c);
void operator= (const CString& c);
void operator= (const char* c);
operator int ();
operator std::string ();
};
// wrapper for the whole interface
class tbwraper
{
protected:
ITBPDataProvider* parent;
public:
tbwraper (ITBPDataProvider* c) : parent(c) {};
tbvalue operator[](int indx) { return tbvalue(parent,indx);};
inline int items() {return parent->ItemCount();};
};
// Exceptions
class ExDataProvider
{
DWORD exnum;
public:
ExDataProvider(DWORD c) : exnum(c) {};
CString msg();
};
// implementations
CString ExDataProvider::msg()
{
CString c;
c.LoadString(exnum);
#ifdef _DEBUG
TRACE(c);
#endif
return c;
}
void tbvalue::operator= (int c)
{
if (parent->SetIntValue(index,c)<0)
throw ExDataProvider(IDS_exnotsupported); // the code of error
// message in the string
resources
};
void tbvalue::operator=(const std::string& c)
{
if (parent->SetDataByID(index, c.c_str(), c.size())<0)
throw ExDataProvider(IDS_exnotsupported);
};
void tbvalue::operator=(const CString& cc)
{
operator=(std::string(cc));
};
void tbvalue::operator=(const char* cc)
{
operator=(std::string(cc));
};
tbvalue::operator int()
{
return parent->GetIntValue(index);
}
tbvalue::operator std::string()
{
DWORD bsize = parent->GetDataByID(index,NULL,-1);
char* b = new char[bsize];
parent->GetDataByID(index,b,bsize);
std::string res(b,bsize);
delete[] b;
return res;
}
#endif // !defined(tbwraper_h)
Usage:
1. Define a line in your resources with index IDS_exnotsupported like
"Exception: this property is read-only."
2. Just use it!
int WINAPI TBP_ExecMacro(void* AMacro, int MaxLen, ITBPDataProvider* Template,
ITBPDataProvider* Params)
{
tbwraper tm(Template);
tbwraper pr(Params);
...
if (pr.items()>0) {// Params->GetItemCount()
std::string res;
for (int i=0; iGetDataByID(index,NULL,-1);
}
tm[0]=res; // Template->SetDataByID(0,res.c_str(),res.size());
return 0;
}
--
Sincerely,
Alexey.
Using TB 2.12.03 on WinXP Pro SP1 (2600), spelling by ORFO2002 (CSAPI)
..with Kaspersky Antivirus Plugin (ver 3.5 Gold) & antispam filter BayesIt! 0.5.7
mailto:[EMAIL PROTECTED]
http://www.silverstones.com/thebat/TBUDLInfo.html