?
Solved

How to read a url protocol in my C application

Posted on 2008-09-29
6
Medium Priority
?
353 Views
Last Modified: 2011-10-19
Have an interesting question and hoping i can find some help here. Let me outline what i need to do.

I need my program to be able to get a value that is in the registry URL that i use to reference it which is currently clayServer://SeatOneA

This correctly opens my application because I have set it up that way in my windows registry but what I need the C application to do is somehow get the SeatOneA value so that if can include it into the if statements and correctly turn on the switches. How might i go about doing this? Thanks so much and if anything is unclear let me know and i will try to explain much better.
/*Application on computer that will control the lighting advice, controls the 4 ports. 
If PA0 changes, k0 switches on or off, program will tell you if it is on or off*/
 
#include "AduHid.h"
#include "stdio.h"  /* for the printf function */
#include <string.h>
 
void * hDevice;
 
void readPort (char[]);
 
void switchAction (char[], char[]);
 
 
/************************************************************* 
 Sets sBufferfer to the reading on the corresponding port
*************************************************************/
void readPort(char portName[])
{
	
	char sBuffer[8];
 
	WriteAduDevice(hDevice, portName, 4, 0, 0);
	memset(sBuffer, 0, sizeof(sBuffer));
	ReadAduDevice(hDevice, sBuffer, 7, 0, 0);
	
	//Calls the switch action function to
	//open/close corresponding k switches
	switchAction(portName, sBuffer);
}
 
/************************************************************* 
 Scans through the PA ports to see which ones are on or off
 If one is on, it will turn on the corresponding K port,
 if one is off, it will make sure the corresponding k port is
 turned off 
*************************************************************/
void switchAction (char name[], char sBuffer[])
{
	if (strcmp(name, "RPA0") == 0)
	{
		 //If PA0 is turned on
		 if (strcmp(sBuffer, "1") == 0)
		 {
		    //Turn on Port K0
			WriteAduDevice(hDevice, "SK0", 4, 0, 0);
		 }
		 else
		 {
			//Close port K0
			WriteAduDevice(hDevice, "RK0", 4, 0, 0);
		 }
	 }
	 
	 if (strcmp(name, "RPA1") == 0)
	 {
		 //If PA1 is turned on
		 if (strcmp(sBuffer, "1") == 0)
		 {
		    //Turn on Port K1
			WriteAduDevice(hDevice, "SK1", 4, 0, 0);
		 }
		 else
		 {
			//Close port K1
			WriteAduDevice(hDevice, "RK1", 4, 0, 0);
		 }
	 }
 
	 if (strcmp(name, "RPA2") == 0)
	 {
		 //If PA2 is turned on
		 if (strcmp(sBuffer, "1") == 0)
		 {
		    //Turn on Port K2
			WriteAduDevice(hDevice, "SK2", 4, 0, 0);
		 }
		 else
		 {
			//Close port K2
			WriteAduDevice(hDevice, "RK2", 4, 0, 0);
		 }
	 }
 
	 if (strcmp(name, "RPA3") == 0)
	 {
		 //If PA3 is turned on
		 if (strcmp(sBuffer, "1") == 0)
		 {
		    //Turn on Port K3
			WriteAduDevice(hDevice, "SK3", 4, 0, 0);
		 }
		 else
		 {
			//Close port K1
			WriteAduDevice(hDevice, "RK3", 4, 0, 0);
		 }
	 }
}
 
int main(int argc, char* argv[])
{
 
	char imputValue[50];
 
 
	while (1)
	{
 
		hDevice = OpenAduDevice(0);
		readPort("RPA0");
		readPort("RPA1");
		readPort("RPA2");
		readPort("RPA3");
		CloseAduDevice(hDevice);
 
	}
 
 
    return 0;
}

Open in new window

0
Comment
Question by:ckehoe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 45

Assisted Solution

by:sunnycoder
sunnycoder earned 80 total points
ID: 22602004
0
 
LVL 1

Author Comment

by:ckehoe
ID: 22607172
Thanks! I will give those a try right now!
0
 
LVL 1

Author Comment

by:ckehoe
ID: 22607604
Will this still work for the setup I have here? (see attatched)

 What i want to get and then use as a variable is the "URL:wayfinding".

and then i want to set it to a char variable so let's say something like this:

char regKey[100] = wayfinding;

if regKey == wayfinding
{
    // turn on port A
}

How can i go about doing this with the code that is used here?
#define DMKEY "Software\\Microsoft" //where to look
 
//store
DWORD rc;
HKEY dmKey;
char szSubKey[1024]; //Key name
char szValue[1024]; //value to set
 
rc = RegOpenKeyEx( HKEY_CURRENT_USER, DMKEY, 0, KEY_ALL_ACCESS, &dmKey );
 
if (rc != ERROR_SUCCESS) {
return ;
}
 
strcpy(szSubKey,"Version1.0");
RegSetValueEx( hkey, szSubKey, 0, REG_SZ, szValue, strlen(szValue)+1 );
 
 
//read
DWORD len;
DWORD dwType;
char sTemp[1024]; //value stored here
char szSubKey[1024]; //Key to be read
len = sizeof(sTemp)
rc = RegOpenKeyEx( HKEY_CURRENT_USER, DMKEY, 0, KEY_ALL_ACCESS, &dmKey );
 
if (rc != ERROR_SUCCESS) {
return ;
}
 
RegQueryValueEx( hkey, szSubKey, 0, &dwType, (LPBYTE)sTemp, &len ); 

Open in new window

regedit.JPG
0
 
LVL 1

Accepted Solution

by:
ckehoe earned 0 total points
ID: 22621899
Found the solution, will post tomorrow.
0
 
LVL 1

Author Comment

by:ckehoe
ID: 22823468
Solution:

#include "AduHid.h"
#include "stdio.h"  /* for the printf function */
#include <string.h>
#include <windows.h>

void * hDevice;

void readPort (char[]);

void switchAction (char[], char[]);

int main(int argc, char* argv[])
{
      HKEY hKey = 0;
      char buf[255] = {0};
      DWORD dwType = 0;
      DWORD dwBufSize = sizeof(buf);
      const char* subkey = "tikiserver3";

      //Open up the key
      if (RegOpenKey(HKEY_CLASSES_ROOT,subkey,&hKey) == ERROR_SUCCESS)
      {
            dwType = REG_SZ;

            if(RegQueryValueEx(hKey,"",0,&dwType, (BYTE*)buf, &dwBufSize) == ERROR_SUCCESS)
            {
                  printf("Your Value is %c \n", buf);
            }
            else
            {
                  printf("Can't find value");
            }
      }
      else
      {
            printf("Can't open Key");
      }
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
Suggested Courses
Course of the Month11 days, 4 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question