news2.homelinux.org
2007-02-21 05:05:19 UTC
Q: Cannot control vista api "SHGetKnownFolderPath" using shell32.dll
in Delphi 7 on Windows XP.
OS: Windows XP
Target: Windows Vista
RAD: Delphi 7 (on Windows XP)
Below code which vista api in shell32.dll as dynamic-loading has
access violation error.
I wanna get user's (shared) folder full path so,
i've coded using vista api "SHGetKnownFolderPath" as a function
pointer by dynamic-load "shell32.dll".
Okay, i think function pointer works good, but i don't know exactly
why write to my array variable(call-by-reference)
at "SHGetKnownFolderPath" in "shell32.dll".
Let me know what is problem. Any help is truly appreciated.
thanks.
Best Regards,
godmode2k
// CODE
//
-------------------------------------------------------------------------------
...
type
TSHGetKnownFolderPath = function(FOLDERID_LocalAppDataLow: TGUID;
dwFlags: DWord; hToken: THandle; ppSzPath: pAnsiChar ) : HResult;
StdCall;
const
PRODUCT_BUSINESS = $00000006;
PRODUCT_HOME_BASIC = $00000002;
PRODUCT_HOME_PREMIUM = $00000003;
PRODUCT_STARTER = $0000000B;
PRODUCT_UNDEFINED = $00000000;
PRODUCT_ULTIMATE = $00000001;
PRODUCT_UNLICENSED = $ABCDABCD;
FOLDERID_LocalAppDataLow : TGUID =
(D1:$A520A1A4; D2:$1780; D3:$4FF6; D4:($BD,$18,$16,$73,$43,$C5,$AF,
$16));
var
...
m_SHGetKnownFolderPath: TSHGetKnownFolderPath;
m_pDllData: Pointer;
m_DllDataSize: Integer;
m_pMemoryModule: PBTMemoryModule;
m_hDll: Cardinal;
...
function BT_SHGetKnownFolderPath_File : BOOL;
begin
m_hDll := LoadLibrary( 'shell32.dll' );
...
@m_SHGetKnownFolderPath := GetProcAddress( m_hDll,
'SHGetKnownFolderPath' );
...
end;
function Vista_GetEnvironment : String;
var
// szPath: pAnsiChar;
szPath: array[0..MAX_PATH] of Char;
ret: HResult;
begin
BT_SHGetKnownFolderPath_File;
//
// Occurs error below line
// Message: Access Violation at address 75F15324 in module
'shell32.dll'. Write of address 16AFC543.
//
ret := m_SHGetKnownFolderPath( FOLDERID_LocalAppDataLow, 0, 0,
szPath );
...
if( m_hDll <> 0 ) then
begin
FreeLibrary( m_hDll );
end;
end;
//
-------------------------------------------------------------------------------
EOF
in Delphi 7 on Windows XP.
OS: Windows XP
Target: Windows Vista
RAD: Delphi 7 (on Windows XP)
Below code which vista api in shell32.dll as dynamic-loading has
access violation error.
I wanna get user's (shared) folder full path so,
i've coded using vista api "SHGetKnownFolderPath" as a function
pointer by dynamic-load "shell32.dll".
Okay, i think function pointer works good, but i don't know exactly
why write to my array variable(call-by-reference)
at "SHGetKnownFolderPath" in "shell32.dll".
Let me know what is problem. Any help is truly appreciated.
thanks.
Best Regards,
godmode2k
// CODE
//
-------------------------------------------------------------------------------
...
type
TSHGetKnownFolderPath = function(FOLDERID_LocalAppDataLow: TGUID;
dwFlags: DWord; hToken: THandle; ppSzPath: pAnsiChar ) : HResult;
StdCall;
const
PRODUCT_BUSINESS = $00000006;
PRODUCT_HOME_BASIC = $00000002;
PRODUCT_HOME_PREMIUM = $00000003;
PRODUCT_STARTER = $0000000B;
PRODUCT_UNDEFINED = $00000000;
PRODUCT_ULTIMATE = $00000001;
PRODUCT_UNLICENSED = $ABCDABCD;
FOLDERID_LocalAppDataLow : TGUID =
(D1:$A520A1A4; D2:$1780; D3:$4FF6; D4:($BD,$18,$16,$73,$43,$C5,$AF,
$16));
var
...
m_SHGetKnownFolderPath: TSHGetKnownFolderPath;
m_pDllData: Pointer;
m_DllDataSize: Integer;
m_pMemoryModule: PBTMemoryModule;
m_hDll: Cardinal;
...
function BT_SHGetKnownFolderPath_File : BOOL;
begin
m_hDll := LoadLibrary( 'shell32.dll' );
...
@m_SHGetKnownFolderPath := GetProcAddress( m_hDll,
'SHGetKnownFolderPath' );
...
end;
function Vista_GetEnvironment : String;
var
// szPath: pAnsiChar;
szPath: array[0..MAX_PATH] of Char;
ret: HResult;
begin
BT_SHGetKnownFolderPath_File;
//
// Occurs error below line
// Message: Access Violation at address 75F15324 in module
'shell32.dll'. Write of address 16AFC543.
//
ret := m_SHGetKnownFolderPath( FOLDERID_LocalAppDataLow, 0, 0,
szPath );
...
if( m_hDll <> 0 ) then
begin
FreeLibrary( m_hDll );
end;
end;
//
-------------------------------------------------------------------------------
EOF