🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Any Suggestions?

Published March 24, 2005
Advertisement
BOOL GetVideoCaptureRegistryValues(VIDEOCAPTUREREGISTRYVALUES* pValues){	BOOL Result=FALSE;	HKEY hKey=NULL;	DWORD dwType=0;	DWORD dwSize=0;	char str[256];	do	{		if(!pValues) break;		if(ERROR_SUCCESS!=RegOpenKeyEx(HKEY_LOCAL_MACHINE,REGISTRY_PATH,0,KEY_QUERY_VALUE,&hKey)) break;		if(!hKey) break;		dwSize=sizeof(str);		if(ERROR_SUCCESS!=RegQueryValueEx(hKey,"CaptureFilterName",NULL,&dwType,(LPBYTE)str,&dwSize)) break;		wsprintfW(pValues->CaptureFilterName,L"%hs",str);		dwSize=sizeof(pValues->AddAudioFilter);		if(ERROR_SUCCESS!=RegQueryValueEx(hKey,"AddAudioFilter",NULL,&dwType,(LPBYTE)&(pValues->AddAudioFilter),&dwSize)) break;		dwSize=sizeof(pValues->BrightnessDefault);		if(ERROR_SUCCESS!=RegQueryValueEx(hKey,"BrightnessDefault",NULL,&dwType,(LPBYTE)&(pValues->BrightnessDefault),&dwSize)) break;		dwSize=sizeof(pValues->BrightnessMaximum);		if(ERROR_SUCCESS!=RegQueryValueEx(hKey,"BrightnessMaximum",NULL,&dwType,(LPBYTE)&(pValues->BrightnessMaximum),&dwSize)) break;		dwSize=sizeof(pValues->BrightnessMinimum);		if(ERROR_SUCCESS!=RegQueryValueEx(hKey,"BrightnessMinimum",NULL,&dwType,(LPBYTE)&(pValues->BrightnessMinimum),&dwSize)) break;		dwSize=sizeof(pValues->ContrastDefault);		if(ERROR_SUCCESS!=RegQueryValueEx(hKey,"ContrastDefault",NULL,&dwType,(LPBYTE)&(pValues->ContrastDefault),&dwSize)) break;		dwSize=sizeof(pValues->ContrastMaximum);		if(ERROR_SUCCESS!=RegQueryValueEx(hKey,"ContrastMaximum",NULL,&dwType,(LPBYTE)&(pValues->ContrastMaximum),&dwSize)) break;		dwSize=sizeof(pValues->ContrastMinimum);		if(ERROR_SUCCESS!=RegQueryValueEx(hKey,"ContrastMinimum",NULL,&dwType,(LPBYTE)&(pValues->ContrastMinimum),&dwSize)) break;		dwSize=sizeof(pValues->HueDefault);		if(ERROR_SUCCESS!=RegQueryValueEx(hKey,"HueDefault",NULL,&dwType,(LPBYTE)&(pValues->HueDefault),&dwSize)) break;		dwSize=sizeof(pValues->HueMaximum);		if(ERROR_SUCCESS!=RegQueryValueEx(hKey,"HueMaximum",NULL,&dwType,(LPBYTE)&(pValues->HueMaximum),&dwSize)) break;		dwSize=sizeof(pValues->HueMinimum);		if(ERROR_SUCCESS!=RegQueryValueEx(hKey,"HueMinimum",NULL,&dwType,(LPBYTE)&(pValues->HueMinimum),&dwSize)) break;		dwSize=sizeof(pValues->SaturationDefault);		if(ERROR_SUCCESS!=RegQueryValueEx(hKey,"SaturationDefault",NULL,&dwType,(LPBYTE)&(pValues->SaturationDefault),&dwSize)) break;		dwSize=sizeof(pValues->SaturationMaximum);		if(ERROR_SUCCESS!=RegQueryValueEx(hKey,"SaturationMaximum",NULL,&dwType,(LPBYTE)&(pValues->SaturationMaximum),&dwSize)) break;		dwSize=sizeof(pValues->SaturationMinimum);		if(ERROR_SUCCESS!=RegQueryValueEx(hKey,"SaturationMinimum",NULL,&dwType,(LPBYTE)&(pValues->SaturationMinimum),&dwSize)) break;		dwSize=sizeof(pValues->ColorSpace);		if(ERROR_SUCCESS!=RegQueryValueEx(hKey,"ColorSpace",NULL,&dwType,(LPBYTE)&(pValues->ColorSpace),&dwSize)) break;		dwSize=sizeof(pValues->BitsPerPixel);		if(ERROR_SUCCESS!=RegQueryValueEx(hKey,"BitsPerPixel",NULL,&dwType,(LPBYTE)&(pValues->BitsPerPixel),&dwSize)) break;		dwSize=sizeof(pValues->OutputWidth);		if(ERROR_SUCCESS!=RegQueryValueEx(hKey,"OutputWidth",NULL,&dwType,(LPBYTE)&(pValues->OutputWidth),&dwSize)) break;		dwSize=sizeof(pValues->OutputHeight);		if(ERROR_SUCCESS!=RegQueryValueEx(hKey,"OutputHeight",NULL,&dwType,(LPBYTE)&(pValues->OutputHeight),&dwSize)) break;		Result=TRUE;	}while(0);	if(hKey)	{		RegCloseKey(hKey);		hKey=NULL;	}	return(Result);}


.... if you've got a cleaner way, I wanna hear it...
Previous Entry Lessons Learned
Next Entry Ack!
0 likes 8 comments

Comments

Jesse Chounard
It looks pretty nice to me. Why do you use BOOL, TRUE, and FALSE instead of the lowercase equivilents?
March 24, 2005 02:10 PM
TANSTAAFL
To fit in with the rest of the Windows code surrounding it.
March 24, 2005 02:22 PM
johnhattan
instead of do { <stuff> } while(0)

could you go with if(true) { <stuff> } ?

Dunno if that'd work.


Another hint for pretty code. If you've got a while-loop with no body (which occasionally happens during a search), you can do this.

while(performaction());

but that's bad form because somebody else looking at it will assume it's a mistake. This also works and it makes it clear that you've got a loop without a body.

while(performaction())
NULL;

Of course, you can always go with

while(performaction())
{
}

But that takes out the fun of being clever.
March 24, 2005 02:22 PM
TANSTAAFL
but you can't break out of the if block like you can with the do while....
March 24, 2005 02:37 PM
VisualLR
I'd make a separate function:



bool QueryValue(HKEY hKey, const char* pValue, LPBYTE* pData, DWORD dwSize)
{
    DWORD dwType = 0;
    int result = RegQueryValueEx(hKey, pValue, NULL, &dwType, pData, dwSize );

    return ( ERROR_SUCCESS == result );
}

// Then just use it like this:

if ( !QueryValue(hKey, "AddAudioFilter", (LPBYTE*)&pValues->AddAudioFilter, sizeof(pValues->AddAudioFilter) )
    break;





It's not all that different, but it makes things a bit easier to read, and it encapsulates functionality that you're currently duplicating.
March 24, 2005 05:02 PM
johnhattan
Ahh, I'd forgotten what break could break out of. If at all possible I avoid using break, as it makes control flow more complicated.

Ditto for calling return except as the last line of a function to return a value.

I don't adhere to 'em religiously, but if it's possible I try.
March 24, 2005 07:16 PM
superpig
This is one of the places that I'd probably use goto. It's no worse than the 'break' thing you've got going on, and it isn't an abuse of the do..while construct.
March 26, 2005 06:20 PM
DigitalDelusion
if you can get away with using some C++ for that I would say

namespace//hide this little helper from the outside world...
{
   	class cReg
	{
		HKEY hKey;
	public:
		cReg(void){	RegOpenKeyEx(HKEY_LOCAL_MACHINE,REGISTRY_PATH,0,KEY_QUERY_VALUE,&hKey);}
		~cReg(void){ if(hKey) RegCloseKey(hKey);}
		operator bool(void) const { return hKey != 0;}
		template <typename T>
		bool QueryValue(const char *name, T &dst)
		{
			DWORD dwSize = sizeof( T), dwType;
			return ERROR_SUCCESS == RegQueryValueEx(hKey,"CaptureFilterName",NULL,&dwType,reinterpret_cast<BYTE*>(&dst),&dwSize);
		}
	};
}

BOOL GetVideoCaptureRegistryValues(VIDEOCAPTUREREGISTRYVALUES* pValues)
{
	cReg Reg;
	if( !pValues || !Reg) return FALSE;
	BOOL Result=FALSE;
	char str[256];

	if( !Reg.QueryValue( "CaptureFilterName", str)) return FALSE;
	if( !Reg.QueryValue( "AddAudioFilter", pValues->AddAudioFilter)) return FALSE;
//...ad infinitum
//all done
	return TRUE;
}

April 04, 2005 12:55 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

Music To My Ears

1883 views

Getting There...

2103 views

Guess Chess

2007 views

iPhone JetLag

1968 views

iPhone JetLag

1797 views
Advertisement