Results 1 to 5 of 5

Thread: [RESOLVED] Accessing Interfaces in VBA

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2021
    Posts
    95

    Resolved [RESOLVED] Accessing Interfaces in VBA

    I am trying to learn how to go about accessing interfaces (such as those used here) in both 32- and 64-bit VBA for my various projects. In my research, I find some code in VBA, but the vast majority seem to require type libraries. Alternatively, it seems that you can access interfaces using some alchemy surrounding the DispCallFunc api.

    TLDR Questions: Can you please recommend/guide me to any resources online that might help me learn how to:
    1. make 64-bit type libraries for use in VBA? and/or;
    2. understand the how's and the why's of using DispCallFunc,
    to access interfaces.

    Type Libraries

    While I have used type libraries very recently in 32-bit Office (VBA7) without any problem, my understanding is that they are bitness dependent - meaning, that there are 32-bit type libraries and 64-bit type libraries, and 64bit Office cant work with 32bit tlbs (and vice versa). fafalone has previously indicated to me on reddit that one can create a 64-bit type library:

    If you have 32bit office, you can use my oleexp.tlb type library, in which I've included VBx compatible versions of all the WebView2 COM interfaces. For 64bit you'd have to make your own TLB or wait until twinBASIC supports exporting TLBs (or do it in twinBASIC, it actually includes a WebView2 sample), when I'll export a 64bit VBA compatible version of tbShellLib, successor to oleexp.
    but frankly, I haven't got the first clue on how to go about doing this, nor have I managed to find any pitched at VBA users trying to make a 64bit type library.

    DispCallFunc

    This is the method I've seen used in VBA (example), and sometimes on this forum (https://www.vbforums.com/showthread....barList-No-tlb), but I don't understand how to use it, or adapt it to my purposes. Each thread I find seem to kick-off at a level more advanced than I can currently follow - for example, with the ITAskbarList example I just referenced, why are the CLSID_TaskbarList, IID_TaskbarList, etc being used and where do I find this sort of information out, and where are these UIDs being source, etc etc etc.

    Why?

    The projects I'm interested in exploring -like fafalone's Modern Shell Interface or The Tricks / Wqweto's DirectX code - all seem to require type libraries... so I keep running into a brick wall.

    Thank you. Any help is appreciated.

  2. #2
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,746

    Re: Accessing Interfaces in VBA

    why use CLSID_TaskbarList、IID_TaskbarList?
    CLSID_TaskbarList like "adodb.stream",you can find on regedit,or by tlbinfo.dll

    it's a com dll,but no tlb for you.
    some com dll only use for vc++,.net ,so vb6 can't use this,because ,vb6 is a soft from 1997,about 25 years ago.

    Many modern DIE features are not supported. So the best way is to wrap it directly with VC++ and then use it for VB6, of course, you may not VC++, so you can only use assembly or pointers, or DispCallFunc and other methods to implement. This requires higher technology. But VB6 can extend its life by another 10-20 years.

    you can study like this:
    vb6 webview2(Edge-Chromium) by IUnknown WebView2Loader.dll-VBForums
    https://www.vbforums.com/showthread....ithout-rc6-dll

    vb6 webview2(Edge-Chromium) by IUnknown WebView2Loader.dll-VBForums
    https://www.vbforums.com/showthread....iew2Loader-dll

  3. #3
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,647

    Re: Accessing Interfaces in VBA

    Sorry for the late reply, I don't check in around this sub often.

    Making typelibs for 64bit *can be* straightforward--- provided you don't want to touch any of the core interfaces and data types defined in oaidl.idl.

    There's two main tools for compiling typelib, the absolutely ancient MKTYPLIB, and midl. midl absolutely refuses to let you redefine anything from oaidl.idl in a VB-compatible way; I've wasted weeks of my life trying to get around the issue by substituting my own oaidl, it eventually dead ended with midl saying effectively 'can't do it. can't provide an error number. can't provide an error source. just can't do it.' MKTYPLIB allows redefinitions with no problem-- but unlike midl, which supports targeting x64, only supports targeting 16 and 32bit.

    Now if you only wanted to use high level interfaces like ITaskBarList et al, there's hope, because you could compile a TLB with that using midl, provided you were careful to avoid using an unsigned data types.

    But this really isn't any easier than using DispCallFunc.

    Right now, if you don't want to wait or devote a substantial block of time to learning some difficult topics, your best option is to use twinBASIC and tbShellLib (which covers 100% of oleexp, which covers all newer DirectX stuff) to implement whatever functionality you're looking for in either an OCX control or DLL (standard or activex; former will be more stable) and use that in VBA. Still a few things to learn to do that but since it's the same language and the same basic approach as making those in VB6, substantially easier than learning the ins and outs of DispCallFunc or all the arcane rules for making a midl-based typelib that will work with VB6/VBA.

    (PS- The GUIDs come from the SDK headers... install the SDK, then when you look up an interface on MS' website, there's a section at the bottom giving the header, the name of the header file where you can find the C++ definition which includes the GUID and correct vtable order)
    Last edited by fafalone; Jun 9th, 2023 at 03:41 AM.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    May 2021
    Posts
    95

    Re: Accessing Interfaces in VBA

    Quote Originally Posted by fafalone View Post
    Sorry for the late reply, I don't check in around this sub often.
    My apologies, I have literally only just seen this. I didn't think anyone had replied. Thank you so much! A lot to digest, but this looks very helpful. I will take a look at it when I get home tonight.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2021
    Posts
    95

    Re: Accessing Interfaces in VBA

    Thank you for your reply - I only just saw that anyone even had!

    Quote Originally Posted by xiaoyao View Post
    why use CLSID_TaskbarList、IID_TaskbarList?
    CLSID_TaskbarList like "adodb.stream",you can find on regedit,or by tlbinfo.dll[/url]
    My apologies for the confusion - those were just intended to be examples.

    I will take a look at the links more closely later tonight (they look like they are the same, though..?)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width