Archive for Programming

Using FreshBooks API from C++

Despite all the new modern languages that are in wide use today, C++ is still my favorite programming language. But, I must admit, it is not always clear how to do some things that may seem trivial in C# or other languages with a huge framework behind.

I assembled a small example that can be used as a starting point for a more complex project that uses the FreshBooks API from C++. You’ll need to have libcurl downloaded and known to your compiler. In the attachment is a very small C++ class that is a wrapper around the C functions from the library.

The program is requesting for the list of clients for a FreshBooks account. Here is a snippet from the code:

/*****************************************************************/
int main(int argc, char* argv[])
{
std::stringstream strReq;
strReq << “<?xml version=\”1.0\” encoding=\”utf-8\”?>”
<< “<request method=\”client.list\”>”
<< “</request>”;

curl::Http ht;
ht.option(CURLAUTH_BASIC, CURLOPT_HTTPAUTH);
ht.option(CURLOPT_USERPWD, “YOUR-TOKEN-HERE”);
ht.option(CURLOPT_URL, “https://YOUR-ACCOUNT-NAME.freshbooks.com/api/2.1/xml-in”);
ht.option(CURLOPT_SSL_VERIFYPEER, 0);
ht.option(CURLOPT_SSL_VERIFYHOST, 2);
ht.option(CURLOPT_PORT, 443);
ht.option(CURLOPT_POSTFIELDS, strReq.str().c_str());

ht.execute();

const std::vector& data = ht.last_response();

std::cout << &data[0] << std::endl;

return 0;
}
/*****************************************************************/

You’ll have to link with libcurl_imp.lib. You should change the connection info with a valid token and account name. I believe that’s it, the program should print the list of clients in the console window.

Comments

My problem with PSH_WIZARD97

I just resolved a programming problem that I was struggling with for the last day and though maybe it could help to somebody else so here it is.

I used CExtResizablePropertySheet from Prof-UIS and everything worked fine. Then suddenly I realized it stopped showing the watermark area altogether with the page title and subtitle. I could swear it worked in my last release. So, I installed it back and yes, it worked. So, it had to be something I changed very recently.

I found out that I changed the WINVER and _WIN32_IE flags to 0×0500, because I wanted to show balloons from the systray. So, this was one possible change, but I could not go back, I needed the balloons. I started debugging the code and I realized that the code execution skips the part in the ProfUIS library where the watermark should be drawn. The check is something like this:

if( (m_psh.dwFlags&(PSH_WIZARD97)) == (PSH_WIZARD97) )

Hm, the ‘if’ condition was never met. Strange, I was certain I set that flag. And yes, I was setting it. But, then I lookup the definition for that flag, and what a surprise, that flag had a different value for Win2000 and up.

#if (_WIN32_IE < 0x0500)
#define PSH_WIZARD97 0x00002000
#else
#define PSH_WIZARD97 0x01000000
#endif

I had compiled the ProfUIS library without 0×0500 for WINVER and _WIN32_IE defined, and that’s why the flags where different. When I compiled my main program, the new value (Win2000 and above) was used, but ProfUIS library was still using the old value. Then I realize, I should recompile the ProfUIS with these flags defined.

Great, now it is same as before.

Comments