Re[2]: The "wrapper" for ITBPDataProvider interface.

2004-07-27 Thread Alexander Leschinsky
Hello Bill,

   On Sun, 25 Jul 2004 12:29:43 -0500 (25.07.2004 23:29 my local time),
   received Tuesday, July 27, 2004 at 9:07:37 +0600,
   you wrote about "The "wrapper" for ITBPDataProvider interface."
   at least in part:

BM> Has anyone written one of these for C?
I know (and use) for Delphi, which can be adapted to C (or used directly
in Builder)
-- 
Best regards,
 Alexander Leschinsky




http://www.silverstones.com/thebat/TBUDLInfo.html


Re: The "wrapper" for ITBPDataProvider interface.

2004-07-25 Thread Bill McCarthy
On Sun 25-Jul-04 1:26am -0400, Alexey N. Vinogradov wrote:

> I've written a small helper "wrapper" on С++ to be used with ITBPDataProvider
> interface. Here is the source:

Has anyone written one of these for C?

-- 
Best regards,
Bill



http://www.silverstones.com/thebat/TBUDLInfo.html


The "wrapper" for ITBPDataProvider interface.

2004-07-24 Thread Alexey N. Vinogradov
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