mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: May 2003
Posts: 7
A
avataru Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
A
Joined: May 2003
Posts: 7
i wanted to find the path to the desktop in XP

i managed to write this, using .com:

Code:
alias _findmydesk {
  var %fmd_name = $+(mydesk,$ticks)
  .comopen %fmd_name WScript.Shell
  if ($comerr == 1) {
    .comclose %fmd_name
    echo -a Closed, error found
    halt
  }
  var %fmd_get = $com(%fmd_name,SpecialFolders,3,bstr,Desktop)
  return $com(%fmd_name).result 
  .comclose %fmd_name
}


the only problem with it is that it crashes mirc (quits) every second time i use the alias. also, when i run it once and then try to go to the remotes (by clicking the remote button) it quits mirc. if i use alt+r, the remote window opens but when i close it, mirc quits.

all help would be appreciated. i am not sure if it's a scripting bug or a mirc bug. i will test in on another computer and see what happens.

update: i tested in a diffrent mIRC on the same computer, it didn't crash... i guess it's somekind of conflict but i am not sure why and where. guess this can be locked.

Last edited by avataru; 22/06/03 12:59 PM.
Joined: Dec 2002
Posts: 5,477
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 5,477
There are two issues here...

First: you are using a /return before the /comclose, which means that /comclose is never called. You must assign the result to a variable, use /comclose, and then return the variable.

Second: I was able to reproduce the gpf, however... since you're passing a bstr value that mIRC has created, the function that you call may try to free the memory associated with that bstr, unless you pass it by reference. That's what seems to be happening.

If you use *bstr, the problem goes away, since mIRC is then able to free the memory that it has allocated without a problem, eg. $com(%fmd_name,SpecialFolders,3,*bstr,Desktop)

Joined: May 2003
Posts: 7
A
avataru Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
A
Joined: May 2003
Posts: 7
doesn't crash anymore, the reason was bstr vs *bstr thanks a lot.

Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
The problem is elsewhere. I looked up the property avataru is trying to use; it turns out that the SpecialFolders property returns the WshSpecialFolders object, which is a collection of special folders. Each special folder in this collection must be retrieved with an index. And even though VBScript samples that MS provides use strings like "AllUsersDesktop" etc, in reality an index number is expected. Using bstr (or *bstr) and a string (like "Desktop") somehow manages to retrieve the first item of the collection (something that probably has to do with the error checking of those functions).

Changing the script to use numbers instead of strings does the trick:
Code:
alias sfolders {
  if $com(blah) { .comclose blah }
  .comopen blah WScript.Shell
  if $comerr { return }
  !.echo -q $com(blah,SpecialFolders,3,uint,$1)
  echo -s $com(blah).result
  .comclose blah
}
Using a little script, I constructed the list of special folders:

AllUsersDesktop
AllUsersStartMenu
AllUsersPrograms
AllUsersStartup
Desktop
ApplicationData
PrintHood
Templates
Fonts
NetHood
Desktop
StartMenu
SendTo
Recent
Startup
Favorites
MyDocuments
Programs

The indexing is zero-based. For example, typing /sfolders 0 echoes the "All Users Desktop" special folder, which is the 1st item in the list. Desktop is represented twice in that list, no idea why.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Mar 2003
Posts: 50
C
Babel fish
Offline
Babel fish
C
Joined: Mar 2003
Posts: 50
Khaled, I was having the same issuses with GPF's and COM. I was wondering if you could clarify a post I made earlier in the Developer Forum as to why this alais crashes. What it attempts to do is, open a browse for folder dialog box. There was 2 issues I had with it.

One, the dialog box would appear and when selecting a folder it returned a 6 digit INT instead of a Folder name. Run the alias again, and mIRC crashed. (which now that has been fixed and no more crashes occur, which is now at the bottom of that post).

Two, not a single person as of yet that I can recall can seem to use unknown/dispatch successfully. Ive tried using various syntax to use it, in which I would expect that I could create a new com object from the dispatch, then be able to access its methods and properties from that point, which when I try to, Im unable to do so. Because of this I cant access the BrowseForFolder().Title property to get the folder name selected, and I cant get the BrowseForFolder() parameters to work when I want it to show a dialog for files and folders.

If you could clarify (because the help file is extemely vague on unknown/dispatch usage, many of us would greatly appreciate it. I can't as of yet clarify my issue as a bug or something Im doing wrong. Heres the post:

Open Dialog using COM

Joined: Jul 2003
Posts: 12
M
Pikka bird
Offline
Pikka bird
M
Joined: Jul 2003
Posts: 12
I'd like to know as well ...


Link Copied to Clipboard