Difference between Declare statement and References?

Banana

split with a cherry atop.
Local time
Yesterday, 20:21
Joined
Sep 1, 2005
Messages
6,318
Trying to implement some custom library, it seems to be suggested that I use the Tools->References where I had expected to use Declare statement instead.

Are they basically same thing, except that Referencing a library would be an implicit declaration and exposes the whole library whereas Declare statement only exposes the needed functions? Other pitfalls I should know about?

Tangentially, has anyone ever compiled a .NET dll into COM-interoperatable library?
 
You can only use Tools-References if the library implements COM.
You'll soon find out by trying to add it.
With references, you get intellisense, type checking, event hooks....
With declare, there is no safety net - get a parameter type wrong, and you can crash your application.
Tangentially, yes - numerous hoops to jump through there.
 
Mearle,

Yes, I would agree that having it exposed via References is handy and safer; I guess I just kinda of assumed that when you use API (e.g. kernel32.dll), it made sense to use Declare, because that's how everyone else did it...

Regarding the .NET library with COM interop enabled- I got it to compile successfully, and am able to use some properties. However the weird thing is that Access's object browsers doesn't expose anything below the top-level members of the library.... I could type in methods or class that's not exposed to object browser and intellisense, and it'd work just fine... I made sure to expose all the hidden members, just in case, but it didn't make any differences. Could it be something wrong with the browser?

For now, I'm switching between the VS and VBA to figure out what I need to call from the library but this is quite time consuming, especially with all the translation I have to do between the two different languages...
 
I guess that some of the "top level" members return other COM objects whose members you want to appear in intellisense.
So, if they work anyway, then they must be late binding.
Check the following in case it is relevant:
http://support.microsoft.com/kb/813809
 
Yup, that would definitely be the cause. Glad to know that this is indeed expected and not because I mangled something in process. That said, it sounds like I'd have to define interfaces for quite a handful of classes with the .NET assembly that it may end up more work than if I keep on trudging by switching between the VS's Object Viewer and VBA's editor.

At least it does show signs that it is working, which is a pleasant news. :)

Thanks!


PS Regarding my earlier post about 'kernel32.dll', would it then follow that it'd make more sense to just add it to references than using Declares if I happen to be using 100s of functions from that library? (I haven't tried that yet, but am not at work computer right now- will have to remember to experiment next time I return)...
 

Users who are viewing this thread

Back
Top Bottom