Click here to Skip to main content
15,891,473 members

Comments by freeluna (Top 2 by date)

freeluna 20-Jan-17 14:31pm View    
This worked great for me. I am a tiny C compiler fan and ended up writing a routine to launch a web page from the command line in windows (suitable for including in a batch file or as a code example). I had to add shellapi.h and create the shell32.def file to get things to compile, but it worked.

-------------------------------------------------------------------
#include <windows.h>
#include <shellapi.h>
#include <string.h>
#include <ctype.h>

// *************************************************
// *
// * If tiny C had a caps insensitive strstr
// * function, This would not be here. This
// * just sets a string to lower case.
// *
// *************************************************
void strToLower_s(char *dest, char *src, int destsize)
{
while(*src!=0 && destsize>1)
{
*dest = (char)tolower(*src);
destsize--;
dest++;
src++;
}
*dest=(char)0;
return;
}


// *************************************************
// * Main routine
// *
// * Usage: http URL ex: http http://www.google.com - or -
// * http www.google.com
// *
// *************************************************
int main(int argc, char *argv[])
{
HINSTANCE h;
char buff[256];

if(argc != 2) return 1;

strToLower_s(buff,argv[1],256);

// check to see if 'http' is in argv[1].
// if so, assume the passed argument is a complete URL.
// otherwise, strap http onto the front of the argument
// and hope for the best.

if(strstr(buff,"http")==NULL)
{
sprintf(buff,"http://%s",argv[1]);
}
h = ShellExecute(NULL,"open",buff,NULL,NULL, SW_SHOWNORMAL);

return 0;
}

------------------------------------------------------
compiled with tinyCC like this:

tcc http.c -lshell32
freeluna 17-Oct-13 16:17pm View    
Reason for my vote of 3 \n I voted for my own article before, so now I'm voting again to compensate.