Skip to content

Instantly share code, notes, and snippets.

@icreatetoeducate
icreatetoeducate / Platform.cpp
Created November 5, 2012 19:15
Check if internet is connected using Win32 API
#pragma comment( lib,"Wininet.lib")
bool Platform::internetConnected() {
DWORD result;
// Check if connected to the internet
if ( InternetGetConnectedState(&result, 0)) {
// Check if we can talk to icreatetoeducate.com
if( InternetCheckConnection("http://icreatetoeducate.com", FLAG_ICC_FORCE_CONNECTION, 0) ) {
return true;
}
}
@icreatetoeducate
icreatetoeducate / Platform.cpp
Created November 5, 2012 19:18
Convert LPWSTR to std::string
bool Platform::convertLPWToString(std::string& s, const LPWSTR pw, UINT codepage = CP_ACP)
{
bool res = false;
char* p = 0;
int bsz;
bsz = WideCharToMultiByte(codepage, 0, pw,-1, 0,0,0,0);
if (bsz > 0) {
p = new char[bsz];
int rc = WideCharToMultiByte(codepage,0,pw,-1,p,bsz,0,0);
@icreatetoeducate
icreatetoeducate / Platform.cpp
Created November 5, 2012 19:20
Copy file to trash using win32 API
bool Platform::CopyFileToTrash( std::string file_path) {
SHFILEOPSTRUCT FileOp;
FileOp.hwnd = NULL;
FileOp.wFunc=FO_DELETE;
FileOp.pFrom= file_path.c_str();
FileOp.pTo = NULL;
FileOp.fFlags=FOF_ALLOWUNDO|FOF_NOCONFIRMATION;
FileOp.hNameMappings=NULL;
int bRet=SHFileOperation(&FileOp);
if( bRet != S_OK )