Friday, January 30, 2015

Fixed: Universal USB Installer syslinux errors

found solution from

https://ardamis.com/2011/09/18/universal-usb-installer-syslinux-errors/


I was trying to create a bootable flash drive with Ubuntu 11.04 using the Universal USB Installer 1.8.6.3 utility from pendrivelinx.com on a Windows 7 64-bit machine with a 16 GB flash drive (mapped to G:), but I kept getting an error that the drive wouldn’t be bootable.
The message in the command line window read:
Execute: C:\Users\[username]\AppData\Local\Temp\[random].tmp\syslinuxnew.exe -maf G:
Syslinux Errors 1
A message box would then appear with the following warning:
Universal USB Installer 1.8.6.3 Setup
An error(1) occurred while executing syslinux.
Your USB drive won’t be bootable…
[OK]
When I opened a command prompt and ran syslinuxnew.exe -maf G:, the result was zero FAT sectors. When I ran syslinux.exe -maf G:, I got a much more informative message, or at least one that I could better understand: this doesn’t look like a valid FAT filesystem.
And of course, the flash drive wasn’t FAT32, it was NTFS. I had forgotten to format the drive as FAT32 before running the utility, but I also managed to not check the box next to “We will format G:\Drive as FAT32.” in the utility itself.
No wonder Google wasn’t returning any results when I searched this – who’s going to have missed properly formatting the drive not once but twice?
In the event that a quick format as FAT32 doesn’t work for you, you can try running a few diskpartcommands in Windows to really thoroughly format a flash drive, including the MBR and partition table.

Saturday, January 17, 2015

Convert int to String or char* yourself


It was asked by an interviewer to me in an interview and I found a bit of equivalent code in


char* version 

char* itoa(int value, char* result, int base) {
  // check that the base if valid
  if (base < 2 || base > 36) { *result = '\0'; return result; }

  char* ptr = result, *ptr1 = result, tmp_char;
  int tmp_value;

  do {
   tmp_value = value;
   value /= base;
   *ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz" [35 + (tmp_value - value * base)];
  } while ( value );

  // Apply negative sign
  if (tmp_value < 0) *ptr++ = '-';
  *ptr-- = '\0';
  while(ptr1 < ptr) {
   tmp_char = *ptr;
   *ptr--= *ptr1;
   *ptr1++ = tmp_char;
  }
  return result;
 }



std::string version



std::string itoa(int value, int base) {

  std::string buf;

  // check that the base if valid
  if (base < 2 || base > 16) return buf;

  enum { kMaxDigits = 35 };
  buf.reserve( kMaxDigits ); // Pre-allocate enough space.


  int quotient = value;

  // Translating number to string with base:
  do {
   buf += "0123456789abcdef"[ std::abs( quotient % base ) ];
   quotient /= base;
  } while ( quotient );

  // Append the negative sign
  if ( value < 0) buf += '-';

  std::reverse( buf.begin(), buf.end() );
  return buf;
 }

Saturday, December 20, 2014

Saturday, December 13, 2014

MSVCRT.DLL causing application to fail loading , application failed to link with msvcrt.dll (entry point not found).

This will happen due to two reason

1) Visual C++  run-time is not installed properly

2) An Operating system  incompatible dll is used with the application (See all dlls are compatible and of correct version).

These may happen when situations like dlls for advanced version of OS is used in a lower version of OS if there is no problem with visual studio run time.

Convert WString to String

#include<stdio.h>
#include<conio.h>
#include<string>
#include<windows.h>

void main( )

{

wstring strWS = L"wstring test";

wprinft("Output before conversion:%s",strWS);

string strConv(strWS .begin( ),strWS .end( ));

printf("Result after conversion:%s",strConv);

_getch( );

}

Error Message: Side-by-side configuration is incorrect

Application/Service does not start and an error message says “The application has failed to start due to a side-by-side configuration error”.

Reason

This happens on computers which do not have Microsoft Visual C++ runtime installed or you are using a debug dll or exe in a system which doesn't have visual studio.


Install all available Windows updates and the latest Windows service pack and check if this already solves the problem.

If this doesn't help, turn off Windows' User Account Control (UAC). Now download and install one of the following packages, depending on which Live version you are using:
Live 32-bit - Microsoft Visual C++ 2008 SP1 Redistributable Package (x86)
Live 64-bit - Microsoft Visual C++ 2008 SP1 Redistributable Package (x64)

Please ensure you only install the 2008 version of the SP1 Redistributable Package as later versions (e.g. 2010) will not resolve this issue.

Reboot your computer and launch Application.
Additional Notes

The issue should not take place anymore with the latest Application updates: from application 9.0.5, the Microsoft Visual C++ is included in the program installer.

Installing the latest Live version will take care of installing this component.

Friday, June 20, 2014

HTTP JSON POST REQUEST C++ EXAMPLE WORKING :-)

#include <Windows.h>
#include <WinInet.h>
#include <tchar.h>
#include<iostream>
#include<stdio.h>
#include<conio.h>
#pragma comment (lib, "Wininet.lib")
#pragma comment (lib, "urlmon.lib")
void Request(LPSTR data);
int main(int argc, _TCHAR* argv[])
{
char data[1024];
char* posturi ="{\"type\":\"Point\",\"coordinates\":[-105.01628,39.57422]}";
wsprintfA( data, posturi);
wsprintfA(data,posturi);
Request(data);
system("pause");
return 0;
}


void Request(LPSTR data)
{
try{
//Retrieve default http user agent
char httpUseragent[512];
DWORD szhttpUserAgent = sizeof(httpUseragent);
//ObtainUserAgentString( 0, httpUseragent, &szhttpUserAgent );

char m[5];


HINTERNET internet = InternetOpen(_T(" Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if(internet==NULL)
{
std::cout<<"InternetOpen failed";
}
if(internet != NULL)
{

HINTERNET connect = InternetConnect(internet, _T("geojsonlint.com"), INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
if(connect==NULL)
{
std::cout<<"InternetConnect failed";
}
if(connect != NULL)
{

HINTERNET request = HttpOpenRequest(connect, _T("POST"), _T("/validate"), _T("HTTP/1.1"), NULL, NULL,
INTERNET_FLAG_HYPERLINK | INTERNET_FLAG_IGNORE_CERT_CN_INVALID |
INTERNET_FLAG_IGNORE_CERT_DATE_INVALID |
INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP  |
INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS |
INTERNET_FLAG_NO_AUTH |
INTERNET_FLAG_NO_CACHE_WRITE |
INTERNET_FLAG_NO_UI |
INTERNET_FLAG_PRAGMA_NOCACHE |
INTERNET_FLAG_RELOAD, NULL);
if(request==NULL)
{
std::cout<<"HttpOpenRequest failed";
}
if(request != NULL)
{
int datalen = 0;
if(data != NULL) datalen = strlen(data);
                LPCWSTR RH=_T("Connection: keep-Alive\r\n");
HttpAddRequestHeaders(request,RH,_tcslen(RH),HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDREQ_FLAG_ADD);
LPCWSTR RH1=_T("Content-Type: application/json\r\n");
HttpAddRequestHeaders(request,RH1,_tcslen(RH1),HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDREQ_FLAG_ADD);
LPCWSTR RH3=_T("Accept-Language: en-US,en;q=0.8\r\n");
HttpAddRequestHeaders(request,RH3,_tcslen(RH3),HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDREQ_FLAG_ADD);
LPCWSTR RH4=_T("Accept: */*\r\n");
HttpAddRequestHeaders(request,RH4,_tcslen(RH4),HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDREQ_FLAG_ADD);
LPCWSTR RH5=_T("Accept-Encoding: gzip,deflate,sdch\r\n");
HttpAddRequestHeaders(request,RH5,_tcslen(RH5),HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDREQ_FLAG_ADD);

HttpSendRequestA(request, NULL, 0, data, datalen);
DWORD StatusCode = 0;
DWORD StatusCodeLen = sizeof(StatusCode);
HttpQueryInfo(request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &StatusCode, &StatusCodeLen, NULL);
if(StatusCode==200)
{
std::cout<<"Sucess=200";
}
else
{
std::cout<<"failed="<<StatusCode;
}

InternetCloseHandle(request);
}
}
InternetCloseHandle(connect);
}
InternetCloseHandle(internet);
}
catch(...) {}
}