Category: C++

C++, libCurl

libcurl – Disable specific Protocols in Windows builds

libCurl – https://curl.haxx.se/docs/install.html The configure utility, unfortunately, is not available for the Windows environment, therefore, you cannot use the various disable-protocol options of the configure utility on this platform. However, you can use the following defines to disable specific protocols: HTTP_ONLY disables all protocols except HTTP CURL_DISABLE_FTP disables FTP CURL_DISABLE_LDAP disables LDAP CURL_DISABLE_TELNET disables TELNET …

C++

Split a char array by delimiter in C++

There are a few ways to accomplish this. //.. char* buffer = "this*is*a*simple*test"; string delimiter = "*"; string s(buffer); size_t pos = 0; string token; while ((pos = s.find(delimiter)) != std::string::npos) { token = s.substr(0, pos); cout<<token<<endl; s.erase(0, pos + delimiter.length()); } cout<<s<<endl; //..//.. char* buffer = "this*is*a*simple*test"; string delimiter = "*"; string s(buffer); size_t …

C++

HTTP POST and GET Requests with WinInet and C++

InternetOpenA InternetConnectA HttpOpenRequestA HttpSendRequestA InternetCloseHandle Method to make POST or GET requests: void Request(int Method, LPCSTR Host, LPCSTR url, LPCSTR header, LPSTR data) { try{ //Retrieve default http user agent char httpUseragent[512]; DWORD szhttpUserAgent = sizeof(httpUseragent); ObtainUserAgentString( 0, httpUseragent, &szhttpUserAgent );   char m[5];   if(Method == GET) strcpy(m, "GET"); else strcpy(m, "POST");   //http://msdn.microsoft.com/en-us/library/windows/desktop/aa385096%28v=vs.85%29.aspx …

C++

Retrieve the User-Agent HTTP

ObtainUserAgentString retrieves the User-Agent HTTP request header string that is currently being used. //.. #pragma comment (lib, "urlmon.lib") //.. char httpUseragent[512]; DWORD szhttpUserAgent = sizeof(httpUseragent); ObtainUserAgentString( 0, httpUseragent, &szhttpUserAgent ); printf("%sn", httpUseragent); //..//.. #pragma comment (lib, "urlmon.lib") //.. char httpUseragent[512]; DWORD szhttpUserAgent = sizeof(httpUseragent); ObtainUserAgentString( 0, httpUseragent, &szhttpUserAgent ); printf("%sn", httpUseragent); //..

C, C++

Threads and Critical Sections in C/C++

InitializeCriticalSectionAndSpinCount Initializes a critical section object and sets the spin count for the critical section. When a thread tries to acquire a critical section that is locked, the thread spins: it enters a loop which iterates spin count times, checking to see if the lock is released. If the lock is not released before the …

C, C++, Python

Integrate python with C/C++ components

ctypes is a foreign function library for Python. It provides C compatible data types, and allows calling functions in DLLs or shared libraries. It can be used to wrap these libraries in pure Python. ctypes exports the cdll, and on Windows windll and oledll objects, for loading dynamic link libraries. You load libraries by accessing …

C++, Linux

Select from SqLite with C++ in Linux

If you are using Ubuntu Linux, you can install sqlite headers by issuing the following command: sudo apt-get install libsqlite3-devsudo apt-get install libsqlite3-dev The code: #include <iostream> #include <sqlite3.h> using namespace std;   static int print_results(void *notInUse, int argc, char **argv, char **colName) { int i; for(i=0; i<argc; i++) cout << colName[i] << " = …