Registry Tip
- These code are let you show how to use API which relevant Windows Registry.
- Registry 에 관련된 것은 이곳에 정리를 해놓는다.
//
// Registry Usage
//
// Visual C++
// ...
// Delphi
uses
..., Registry;
procedure TEST_RegistryRW;
var
__REG: TRegistry;
str: string;
strREGKeyVal: string;
strNewKey: string;
begin
str := 'SOFTWARE\TEST' + '\REG_TEST';
strNewKey := 'TestKey';
__REG := TRegistry.Create( KEY_WRITE );
try
//__REG.RootKey := HKEY_LOCAL_MACHINE;
__REG.RootKey := HKEY_CURRENT_USER;
__REG.OpenKey( str, True );
__REG.WriteString( strNewKey, 'can you see this?' );
finally
__REG.Free;
ShowMessage( 'WRITE: finish' );
end;
__REG := TRegistry.Create( KEY_READ );
try
//__REG.RootKey := HKEY_LOCAL_MACHINE;
__REG.RootKey := HKEY_CURRENT_USER;
__REG.OpenKey( str, True );
strREGKeyVal := __REG.ReadString( strNewKey );
if( strREGKeyVal <> '' ) then ShowMessage( 'String: ' + strREGKeyVal );
finally
__REG.Free;
ShowMessage( 'READ: finish' );
end;
end;
// ---------------------------------------------------
//
// Checks Registered Object
//
// Visual C++
#include // Ole32.lib, Ole32.dll
CLSID ClsID;
char* pStrProgID = "Object.InterfaceName"; // Hello.Application
RESULT hr = CLSIDFromProgID( pStrProgID, &ClsID);
if( hr == S_OK )
// Registered
else
// Not Registered
// Delphi
uses
..., ActiveX;
procedure TEST_ChecksRegisteredObject
var
ClassID: TGUID;
strObject: string;
begin
strObject := 'Object.InterfaceName'; // Hello.Application
if( CLSIDFromProgID(PWideChar(WideString(strObject)), ClassID) = S_OK ) then begin
ShowMessage( 'Registered' );
end
else begin
ShowMessage( 'Not Registered' );
end;
end;
-----
Cheers,
June
댓글 없음:
댓글 쓰기