Need help with IShellLink

BlitzMax Forums/BlitzMax Programming/Need help with IShellLink

beanage(Posted 2010) [#1]
Hey,

I want to create a desktop shortcut. Therefore, I use bmx EXTERN to get the COM IShellLink class. I call CoCreateInstance() to retreive a new IShellLink object. Tests revealed CoInitialize() has already been executed by BlitzMax. I use SHGetSpecialFolder() to get the desktop directory. I call methods of the windows IShellLink class to set appropriate parameters. I utilize the IPersistFile Class to save the object.

Now, everything works fine, until at some point a EXCEPTION_ACCESS_VIOLATION occurs, mostly at pPersistFile.Save(). In addition, I am not sure whether i wrapped the methods correctly (do i need to pass this* to the method as well? are they correctly exposed in the extern block?)... I am also not sure whether I should use wide strings with "$w" or with ":Short Ptr" or not using wide strings at all... much room for error. [Edit: I think the key problem really is how I expose the COM methods, but I really dont know how to fix it :{ ]

I'd be glad if someone could take an analyzing look at that code:



grable(Posted 2010) [#2]
No need to declare IUnknown, its already in PUB.Win32 together with some other COM related stuff.

All methods return Int not Long.
Never pass or declare Self.
All methods must be declared in order, you cant pick and choose which ones you want.

And for Strings its usually ok to use $w for in-args, and Short Ptr for in/out-args.

Take a look at PUB.Win32\com.bmx and PUB.DirectX\* for examples.

I tried to get your example to work though..
But it complains about missing CoCreateInstance even though i know its there :( weird.

edit: hmm.. seems PUB.Win32 doesnt import Ole32 ??? it worked after i imported it myself. (but your example still crashes)


Brucey(Posted 2010) [#3]
COM stuff is fun in BlitzMax :-p


grable(Posted 2010) [#4]
COM stuff is fun in BlitzMax :-p
Hehe, so true :P

You had the wrong IIDs for both IShellLinkW and IPersistFile so no wonder i was getting errors ;)

Heres a modified (and working) version of your example.


edit: Oh. and btw, if you ever need to figure out the layout of an interface and you have MinGW. check out shlobj.h and objidl.h.


beanage(Posted 2010) [#5]
@grable: IT WORKS!!!!! IT WORKS!!! I.T. D.O.E.S. W.O.R.K.!!!!! :}}}

I can barely express how you helped me there buddy, but this is awesome :D And I learned something. Thanks for pointing me to Pub.Win32. Thanks for digging into my buggy code, thanks for pointing me to all the incorrectness i did importing the methods. Thanks for finding the errors in my IIDs - and after all; NOBODY WILL EVER HAVE THIS PROBLEM AGAIN! Another precious code snippet recorded in these wonderful forums, thanks to you!

[Hehe, and after all I'm proud, that at least a few lines of mine reappeared in your fix :P]

@Brucey: yea its always a bit of evil wakeup for me as a blitzer, when I step out of my candy MaxIDE paradise back into the big, dark and cold C reality of those windows APIs :)