Question about Prototypes and calling a function

Windows specific forum
jacky
User
User
Posts: 58
Joined: Mon Jan 21, 2019 1:41 pm

Question about Prototypes and calling a function

Post by jacky »

Hi,

I want to be able to call this function from shell32.dll: SHParseDisplayName
https://docs.microsoft.com/en-us/window ... isplayname

I'm trying it like this and the program crashes when I execute it :oops:

Code: Select all

Prototype.i ProtoSHParseDisplayName(pszName.p-unicode, *pbc, *ppidl, sfgaoIn.i, *psfgaoOut)

Define.i hShell32DLL
Define SHParseDisplayName.ProtoSHParseDisplayName

hShell32DLL = OpenLibrary(#PB_Any, "Shell32.dll")
If hShell32DLL
  SHParseDisplayName.ProtoSHParseDisplayName = GetFunction(hShell32DLL, "SHParseDisplayName")
EndIf

Define *pidl.ITEMIDLIST

hResult = SHParseDisplayName("R:\test_folders\00001", 0, *pidl, 0, 0)
If hResult = #S_OK
  Debug "OK!"
EndIf

I'm obviously doing it wrong, can anybody tell me how to do it right?
User avatar
JHPJHP
Addict
Addict
Posts: 1787
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Question about Prototypes and calling a function

Post by JHPJHP »

Hi jacky,

Change:

Code: Select all

hResult = SHParseDisplayName("R:\test_folders\00001", 0, *pidl, 0, 0)
To:

Code: Select all

hResult = SHParseDisplayName("R:\test_folders\00001", 0, @pidl, 0, 0)

STATUS: Mostly Unavailable :: Downloads moved to My PureBasic Stuff; access key required.
_________________
jacky
User
User
Posts: 58
Joined: Mon Jan 21, 2019 1:41 pm

Re: Question about Prototypes and calling a function

Post by jacky »

Hi JHPJHP,

after additionally changing

Code: Select all

Define *pidl.ITEMIDLIST
to

Code: Select all

Define pidl.ITEMIDLIST
it ... works!

Thanks a lot!
User avatar
skywalk
Addict
Addict
Posts: 3514
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Question about Prototypes and calling a function

Post by skywalk »

@*pidl works also.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
jacky
User
User
Posts: 58
Joined: Mon Jan 21, 2019 1:41 pm

Re: Question about Prototypes and calling a function

Post by jacky »

Yes, skywalk, you're right, it's also working that way :D

The whole calling that function thing can't be accelerated in any way, right?

I'm asking because doing that call with a list of 20.000 folder entries takes about 2,75 seconds alone.

v5.70 x64, compiled .exe

Windows Explorer must use some kind of different way to build the shell context menu. Clicking on 20.000 selected
folders with the right mouse button shows the context menu instantly...
User avatar
skywalk
Addict
Addict
Posts: 3514
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Question about Prototypes and calling a function

Post by skywalk »

Windows is the operating system and indexes files and folders in the background. To duplicate that in code requires a database and threads.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Post Reply