• Advertisement
Sign in to follow this  
  • entries
    292
  • comments
    557
  • views
    153871

Any Suggestions?

Sign in to follow this  

115 views


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...
Sign in to follow this  


8 Comments


Recommended Comments

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.

Share this comment


Link to comment
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.

Share this comment


Link to comment
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.

Share this comment


Link to comment
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.

Share this comment


Link to comment
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;
}

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement