Solved

How to read a url protocol in my C application

Posted on 2008-09-29
6
347 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
  • 4
6 Comments
 
LVL 45

Assisted Solution

by:sunnycoder
sunnycoder earned 20 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

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