Solved

How to read a url protocol in my C application

Posted on 2008-09-29
6
346 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to find a data that is pure string   or not in vb.net ? 9 103
Where is my core dump file in Ubuntu? 12 442
Socket Programming (Unix) 8 118
Resolve Dependency Issues 4 44
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…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

911 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now