[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 356
  • Last Modified:

How to read a url protocol in my C application

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
ckehoe
Asked:
ckehoe
  • 4
2 Solutions
 
ckehoeAuthor Commented:
Thanks! I will give those a try right now!
0
 
ckehoeAuthor Commented:
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
 
ckehoeAuthor Commented:
Found the solution, will post tomorrow.
0
 
ckehoeAuthor Commented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now