PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
[RESOLVED] Looking for advice on 64-Bit COM-VBForums
Results 1 to 27 of 27

Thread: [RESOLVED] Looking for advice on 64-Bit COM

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    1,279

    Resolved [RESOLVED] Looking for advice on 64-Bit COM

    I have a small application coded in VB6 that sits alongside my main application that acts as a bridge between my app & Microsoft Outlook. I execute the small app with some command-line parameters and extra data in a memory mapped file, and it handles the Outlook automation in the background using Outlook Redemption* then spits back results to my main app when operations are completed. This has all worked nicely for years provided the 32-bit version of Office/Outlook is installed.

    It used to be that even Microsoft recommended using the 32-bit version of Office unless you had some specific reason to use the 64-bit version, but it looks like they've changed their tune on that recently and are even defaulting to 64-bit for new installs of Office 365 subscriptions. Needless to say, it's becoming a bit of a pain dealing with increasing numbers of support requests, getting people to uninstall the 64-bit version, and install the 32-bit version, etc... To top it off, more users are now insisting on using the 64-bit version, so I suspect it's only going to get more difficult to convince anyone to go back to 32-bit going forward. C'est la vie!

    The good news is that Outlook Redemption has a 64-bit version of its library, so I'm hoping for a simple way to use it. AFAIK this will not be possible with VB6, but I'm happy to be corrected here (in fact I'd be ecstatic to be corrected here!).

    Assuming I have to move to something non-VB6, I've been poking around the Internet looking for a solution that ideally:

    • Is free (as in beer more than as in speech).
    • Is a BASIC dialect for relatively painless translation.
    • Compiles to a 64-bit EXE.
    • Does not require .Net runtimes (or any runtimes for that matter).
    • Supports COM DLLs (ideally regfree).


    I've stumbled across FreeBasic which looks promising - it seems to check all the boxes above, however every included COM example fails to compile with warnings about missing declarations (even when I've included what appear to be the appropriate .BI files with the constants/variables declared).

    I'm willing to continue fighting with FreeBasic until I get it to work, but before I get too deep I was wondering if any of you have had any experience migrating a VB6 app to another 64-bit BASIC? If so, what did you use? If you used FreeBasic, do you have any advice on how to get things to compile that work against the Windows APIs & a COM DLL?

    Thanks in advance for any help.



    * Not sure if I'm allowed to post this link since it is a commercial library, but I thought it might be useful to those who are unfamiliar with the library. Happy to remove the link if mods want.

  2. #2
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    287

    Re: Looking for advice on 64-Bit COM

    why is vb.net\c# a deal breaker?

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    1,279

    Re: Looking for advice on 64-Bit COM

    .Net is not a necessarily a deal breaker, just not my ideal choice. My reasons being (and these may be misguided, my .Net experience is minimal):

    • The helper app will launched fairly frequently and should initialize, run, and terminate as quickly as possible - I am hoping for something lightweight. It feels like the overhead of a big run-time might impact me negatively here.
    • I don't want to distribute anything other than my app, or ask anyone to install anything other than my app. Now AFAIK the .Net runtime is nearly ubiquitous these days so maybe this is a non-issue, but it's just another potential point of failure/complication that I would like to try to avoid if possible.


    If it turns out .Net is the best choice, so be it.

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    1,279

    Re: Looking for advice on 64-Bit COM

    One other thing that just came to mind about .Net/VisualStudio - can you use the "community/express/whatever they are calling it these days" edition for commercial projects, or do you have to purchase a license?

  5. #5
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,199

    Re: Looking for advice on 64-Bit COM

    I believe it can be used for commercial products, as long as it is a single programmer that is producing the product, but I could be misinterpreting the license agreement.

    I agree that for a program that starts up, does something quick, and then exits, will be slower with .Net. The executable contains CLI code that will be converted into native code each time it is run, so you have that overhead each time you run, regardless of whether the RunTime libraries are already loaded in memory from earlier runs, or because of other applications using them.

    How much impact that is from the users standpoint, ...?
    Last edited by passel; May 15th, 2019 at 12:17 PM.

  6. #6
    Hyperactive Member
    Join Date
    Feb 2019
    Posts
    368

    Re: Looking for advice on 64-Bit COM

    Edit: Please see post #24 below for an updated code.

    I have done something similar. I had a 64 Bit COM DLL that I wanted to talk to. The way it's done is by calling the API version of CreateObject(), and asks it to use the 64-Bit Dllhost.exe to host the 64-Bit COM DLL, then talk to it. This requires adding a registry entry at install time so Dllhost.exe is used. The value is of type String, and it should be left empty. Here is the registry entry that you need to create:

    HKEY_LOCAL_MACHINE\SOFTWARE\Classes\APPID\{AppID_value}
    DllSurrogate=""

    To use CreateObject64() below, you call it like this:

    Dim o64 As Object

    Set o64 = CreateObject64("Project1.Class1")

    There is no error handling, but you could add Err.Raise, or add an extra ByRef parameter to return error information.

    VB Code:
    1. Public Type TGUID
    2.    Data1 As Long
    3.    Data2 As Integer
    4.    Data3 As Integer
    5.    Data4(7) As Byte
    6. End Type
    7.  
    8. Public Const CLSCTX_INPROC_SERVER As Long = 1
    9. Public Const CLSCTX_INPROC_HANDLER As Long = 2
    10. Public Const CLSCTX_LOCAL_SERVER As Long = 4
    11. Public Const CLSCTX_ENABLE_AAA As Long = &H10000
    12. Public Const CLSCTX_REMOTE_SERVER As Long = 16
    13. Public Const CLSCTX_SERVER As Long = (CLSCTX_INPROC_SERVER Or CLSCTX_LOCAL_SERVER)
    14. Public Const CLSCTX_ALL As Long = (CLSCTX_INPROC_SERVER Or CLSCTX_INPROC_HANDLER Or CLSCTX_LOCAL_SERVER)
    15. Public Const IID_IUnknown As String = "{00000000-0000-0000-C000-000000000046}"
    16. Public Const IID_IDispatch As String = "{00020400-0000-0000-C000-000000000046}"
    17.  
    18. Public Declare Function CoCreateInstance Lib "OLE32.DLL" (ByVal rclsid As Long, ByVal punkOuter As Long, ByVal dwClsContext As Long, ByVal riid As Long, ByRef ppv As Any) As Long
    19. Public Declare Function CLSIDFromString Lib "OLE32.DLL" (ByVal lpsz As Long, ByRef pCLSID As TGUID) As Long
    20. Public Declare Function CLSIDFromProgID Lib "OLE32.DLL" (ByRef TSzProgID As String, ByRef pCLSID As TGUID) As Long
    21. Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
    22.  
    23. Public Function CreateObject64(ByRef sObjectName As String) As Object
    24.     Dim ret As Long
    25.     Dim pCLSID As TGUID
    26.     Dim IIDispatch As TGUID
    27.     Dim ppv As Long
    28.  
    29.     ret = CLSIDFromString(StrPtr(IID_IDispatch), IIDispatch)
    30.     ' Get object by GUID
    31.     'ret = CLSIDFromString(StrPtr("{11111111-2222-3333-4444-555555555555}"), pCLSID)
    32.     ' Get object by ProgID
    33.     ret = CLSIDFromProgID(StrPtr(sObjectName), pCLSID)
    34.    
    35.     If ret = 0 Then
    36.         ' Success
    37.        
    38.         ' Create Object
    39.         ret = CoCreateInstance(VarPtr(pCLSID), 0, CLSCTX_LOCAL_SERVER, VarPtr(IIDispatch), ppv)
    40.        
    41.         'Debug.Print "CoCreateInstance returned = " & Hex(ret) & ", ppv = " & Hex(ppv) & ", LastDllError = " & Err.LastDllError
    42.        
    43.         If ppv <> 0 Then
    44.             Set CreateObject64 = ObjFromPtr(ppv)
    45.         End If
    46.     Else
    47.         Debug.Print "CLSIDFromString failed, ret = " & Hex(ret) & ", LastDllError = " & Err.LastDllError
    48.     End If
    49.  
    50. End Function
    51.  
    52. ' Returns an object given its pointer
    53. ' This function reverses the effect of the ObjPtr function
    54. Public Function ObjFromPtr(ByVal pObj As Long) As Object
    55.     Dim obj As Object
    56.     ' force the value of the pointer into the temporary object variable
    57.     CopyMemory obj, pObj, 4
    58.     ' assign to the result (this increments the ref counter)
    59.     Set ObjFromPtr = obj
    60.     ' manually destroy the temporary object variable
    61.     ' (if you omit this step you'll get a GPF!)
    62.     CopyMemory obj, 0&, 4
    63. End Function
    Last edited by qvb6; May 16th, 2019 at 11:17 AM.

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    1,279

    Re: Looking for advice on 64-Bit COM

    Hi qvb6, thanks a lot, this looks very promising!

    One question I have about the App.Id - at install time do I create an registry entry for my Executable file name, e.g.

    Code:
    Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Classes\AppID\MyAppFileName.exe
    Then create a subkey of that called "AppID" with a GUID that I generate myself?

    Next I would add another registry key:

    Code:
    Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Classes\AppID\{GuidIGeneratedAndStoredInMyAppFilename/AppID}
    And then create a subkey of that call DllSurrograte with an empty string value. Is that correct?

    Is there anything I need to do to put the AppId in my EXE, or does Windows get the AppId from the registry automatically based solely on the filename?

  8. #8
    Hyperactive Member
    Join Date
    Feb 2019
    Posts
    368

    Re: Looking for advice on 64-Bit COM

    No, you need to search the registry for Outlook Redemption after installing the 64-Bit version of it, and add DllSurrogate to it, not your app.

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    1,279

    Re: Looking for advice on 64-Bit COM

    Ahh I see, thanks for the clarification! I'll give it a shot, appreciate the help

  10. #10
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    287

    Re: Looking for advice on 64-Bit COM

    Quote Originally Posted by passel View Post
    I believe it can be used for commercial products, as long as it is a single programmer that is producing the product, but I could be misinterpreting the license agreement.
    number or programmers doesn't matter. You need the pro license if you are over 1 million a year in revenue or have more than 250 computers at your business

  11. #11
    Hyperactive Member
    Join Date
    Feb 2019
    Posts
    368

    Re: Looking for advice on 64-Bit COM

    I should have renamed CreateObject64() to CreateObjectOutOfProcess(), because it has nothing really to do with 64-Bit. It can be used to start a 32-Bit COM DLL/OCX out of process, for example, if the DLL/OCX is buggy and crashes, it doesn't impact your EXE other than getting a runtime error. This technique is used by web servers so a bad DLL doesn't crash the server.

    Also, I tweaked the function a little before posting it as I was using GUID rather than a name to instantiate the object. The commented out CLSIDFromString() call is the one I was using and testing with. I hope that my tweaks didn't break things, I only tested it to make sure it compiles.

  12. #12
    Hyperactive Member
    Join Date
    Feb 2019
    Posts
    368

    Re: Looking for advice on 64-Bit COM

    Quote Originally Posted by DllHell View Post
    number or programmers doesn't matter. You need the pro license if you are over 1 million a year in revenue or have more than 250 computers at your business
    This is mentioned here(Under "Supported Usage Scenarios"):

    https://visualstudio.microsoft.com/vs/compare/

  13. #13

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    1,279

    Re: Looking for advice on 64-Bit COM

    Thanks for the VisualStudio licensing clarifications everyone!

    Looks like Redemption64.dll doesn't have an AppId when you register it, but as per this StackOverflow thread it looks like you can just use the CLSID as the AppID. I've tried it out quickly and it looks like basic calls are working, but I have to do some more in-depth testing to ensure I'm actually using the 64-bit DLL (I have both on this system, so I might be hitting the 32-bit accidentally - must confirm so I won't mark this resolved yet).

    That said, this looks great so far. Thank you very much qvb6!

  14. #14
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,279

    Re: Looking for advice on 64-Bit COM

    Another possibility would be to use VBScript as the "Execution-Host" for the 64Bit-Redemption-Dll...
    (*.vbs-Files will be started in a 64Bit-Host-Process by default on 64Bit-Windows).

    To make a given Dll regfree usable via VBScript (or also *.asp):
    - one needs to place a MyDllName.manifest file besides the Dll
    - and then use the following VBScript-Block, to instantiate an SxS-Helper:
    Code:
    Dim SxS
    Set SxS = CreateObject("Microsoft.Windows.ActCtx") 'create the SxS-Helper-Obj
        SxS.Manifest = "Redemption.manifest" 'specify the path to the manifest-file of the Dll
    
    Dim Itm   'now create Objects regfree by using the CreateObject-Method of the SxS-Helper
    Set Itm = SxS.CreateObject("Redemption.SafeMailItem")
    The xml-content for the SxS-manifest-file of the Redemption-Dll would be the following:
    Code:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
      <file name="Redemption.dll">
        <comClass clsid="{4fd5c4d3-6c15-4ea0-9eb9-eee8fc74a91b}" threadingModel="Apartment" progid="Redemption.SafeContactItem" />
        <comClass clsid="{620d55b0-f2fb-464e-a278-b4308db1db2b}" threadingModel="Apartment" progid="Redemption.SafeAppointmentItem" />
        <comClass clsid="{741beefd-aec0-4aff-84af-4f61d15f5526}" threadingModel="Apartment" progid="Redemption.SafeMailItem" />
        <comClass clsid="{7a41359e-0407-470f-b3f7-7c6a0f7c449a}" threadingModel="Apartment" progid="Redemption.SafeTaskItem" />
        <comClass clsid="{c5aa36a1-8bd1-47e0-90f8-47e7239c6ea1}" threadingModel="Apartment" progid="Redemption.SafeJournalItem" />
        <comClass clsid="{fa2cbafb-f7b1-4f41-9b7a-73329a6c1cb7}" threadingModel="Apartment" progid="Redemption.SafeMeetingItem" />
        <comClass clsid="{11e2bc0c-5d4f-4e0c-b438-501ffe05a382}" threadingModel="Apartment" progid="Redemption.SafePostItem" />
        <comClass clsid="{4a5e947e-c407-4dcc-a0b5-5658e457153b}" threadingModel="Apartment" progid="Redemption.MAPIUtils" />
        <comClass clsid="{03c4c5f4-1893-444c-b8d8-002f0034da92}" threadingModel="Apartment" progid="Redemption.MAPIFolder" />
        <comClass clsid="{7ed1e9b1-cb57-4fa0-84e8-fae653fe8e6b}" threadingModel="Apartment" progid="Redemption.SafeCurrentUser" />
        <comClass clsid="{7c4a630a-de98-4e3e-8093-e8f5e159bb72}" threadingModel="Apartment" progid="Redemption.SafeDistList" />
        <comClass clsid="{37587889-fc28-4507-b6d3-8557305f7511}" threadingModel="Apartment" progid="Redemption.AddressLists" />
        <comClass clsid="{a6931b16-90fa-4d69-a49f-3abfa2c04060}" threadingModel="Apartment" progid="Redemption.MAPITable" />
        <comClass clsid="{d46ba7b2-899f-4f60-85c7-4df5713f6f18}" threadingModel="Apartment" progid="Redemption.SafeReportItem" />
        <comClass clsid="{ed323630-b4fd-4628-bc6a-d4cc44ae3f00}" threadingModel="Apartment" progid="Redemption.SafeInspector" />
        <comClass clsid="{29ab7a12-b531-450e-8f7a-ea94c2f3c05f}" threadingModel="Apartment" progid="Redemption.RDOSession" />
      </file>
    </assembly>
    Not sure whether that can make your "shelled Mini-Executable" obsolete - but *.vbs Files should be "shellable" nicely...
    (and - FWIW - could be generated on the fly - before shelling them).

    HTH

    Olaf

  15. #15

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    1,279

    Re: Looking for advice on 64-Bit COM

    Hi Olaf, that looks like a great approach too. I especially like the fact that it can run regfree (which was one of points on my "ideal" list). I suppose a potential drawback is that some sites may be blocking execution of VBS files by disabling Windows Script Host, but I'll have to check with the customers to see if that's the case. Thanks a lot for that example!

  16. #16
    Frenzied Member
    Join Date
    Sep 2012
    Posts
    1,574

    Re: Looking for advice on 64-Bit COM

    Maybe we need to face more and more 64-Bit COMs in the future.

  17. #17
    Hyperactive Member
    Join Date
    Jan 2015
    Posts
    283

    Re: Looking for advice on 64-Bit COM

    Good post, as like dreammanor is saying we will face more & more this in the future and finding a generic solution will be good.
    I also begin to face the same problem with Outlook or Excel
    the vbs idea should be promising.

    The problem is that we need a development computer with 64 bits installed

    I'll start to investigate a bit too

  18. #18
    Frenzied Member
    Join Date
    Feb 2017
    Posts
    1,708

    Re: Looking for advice on 64-Bit COM

    I was able to use Word automation from VB6 with Office Word 64 bits with normal code also used to handle 32 bits versions...

  19. #19
    Hyperactive Member
    Join Date
    Feb 2019
    Posts
    368

    Re: Looking for advice on 64-Bit COM

    It looks like the Redemption DLL developers were lazy and didn't add an AppID key(It's optional, but needed for out-of-process activation as listed in the first item here), which means that someone has to add it, then tell each of the 16 Objects it contains the AppID it belongs to by adding "AppID" value underneath the CLSID of each object. I try to do that if I have the time and post back.
    Last edited by qvb6; May 16th, 2019 at 11:18 AM.

  20. #20

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    1,279

    Re: Looking for advice on 64-Bit COM

    Just a quick update.

    I've been trying qvb6's approach re: AppId on a fresh system with Outlook 64-bit installed, and so far I haven't been able to get it to work (whereas it seemed to work on my main dev system with Outlook 32-bit installed). I still have some more experimenting to do here, it's possible I got something wrong with my registry. Long and short of this approach though for those stopping by from the future - if you getting working the plus side is that you won't have to change much of your existing VB6 code. The downside is that you will have to use the registry, so reg-free is a no-go.

    I've also just got Olaf's VBS approach working. One plus sides are that I can dynamically generate a script with all the appropriate email addresses, attachments, etc... so I don't need to create a mapped file for shared storage/passing data to a separate process. Another plus is that it can work reg-free. The only downside I can think of is IF VBS scripts are blocked on an end user's machine. I don't know how common this is, though I have heard people complain about it, so it is definitely a potential concern. Another downside is that I had to rewrite some swaths of code, but the transition to VBScript is relatively painless and my helper app was quite small, so not a big deal overall.

    Last thing about Olaf's VBS approach I have to figure out is if I can easily pass data back to my VB6 app from a VBS...I suppose one easy (if ugly) way would be to save the data to a file in the TMP folder and then just watch for it on the VB6 side and slurp it in. Anyway, this part is a bit off-topic so I will do some research and try to find a good solution.


    Thanks again to everyone for your help and advice. This exercise turned out to be quite a bit easier than I thought it would thanks to you!

  21. #21
    Addicted Member
    Join Date
    Feb 2015
    Posts
    165

    Re: Looking for advice on 64-Bit COM

    @jpbro @qvb6

    The Outlook Redemption developers are usually helpful. It may be worth contacting them http://www.dimastr.com/redemption/home.htm

  22. #22

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    1,279

    Re: Looking for advice on 64-Bit COM

    Quote Originally Posted by dreammanor View Post
    Maybe we need to face more and more 64-Bit COMs in the future.
    Quote Originally Posted by Thierry69 View Post
    Good post, as like dreammanor is saying we will face more & more this in the future and finding a generic solution will be good.I also begin to face the same problem with Outlook or Excel
    Yes I think we will be seeing more of 64-Bit Office unfortunately - especially now that Microsoft appears to be endorsing it over 32-bit, which is a change from their previous stance. It used to be we could point IT to Microsoft's page that recommended 32-bit over 64-bit unless you had special needs that only the 64-bit version would support, but that's ammunition we no longer have.

  23. #23

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    1,279

    Re: Looking for advice on 64-Bit COM

    Quote Originally Posted by VB6 Programming View Post
    @jpbro @qvb6

    The Outlook Redemption developers are usually helpful. It may be worth contacting them http://www.dimastr.com/redemption/home.htm
    Thanks VB6Programming - I've been considering contacting Dmitry (Redemption Dev) as I have a support license, but I wanted to collect some more information/run some more tests before doing so. But I agree, the support for Redemption is excellent.

  24. #24
    Hyperactive Member
    Join Date
    Feb 2019
    Posts
    368

    Re: Looking for advice on 64-Bit COM

    I made some progress, but I don't have Outlook to test. I am getting error 0x8004010F from CoCreateInstance(), which is an Outlook related error according to this page. I also found about a new flag called CLSCTX_ACTIVATE_64_BIT_SERVER.

    To try this code, you need to add the registry entries in the attached RegAppIDRedemption.reg first(I included another file to remove these entries). Compile, and run the program from the EXE, not the IDE; because the IDE is running as Admin. I see an extra dllhost.exe process, and it's the 64-Bit version, I also see Redemption license agreement. In the registry file, I made a new GUID as the AppID, so you won't find it anywhere on the web. I used the list provided by Olaf and a spreedsheet to quickly create the registry entries. I couldn't make it work with ProgID("Redemption.RDOSession"), so I had to use GUID's, but I made constants to use instead of using GUID that you will find at the top of Module1. There are probably more objects needed, but I am not sure. All the code is in Module1.

    OutlookRedemptionTest1.zip

  25. #25

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    1,279

    Re: Looking for advice on 64-Bit COM

    Hi @qvb6 - nice work I think the CLSCTX_ACTIVATE_64_BIT_SERVER flag might have been the trick because I was getting errors with a same/similar REG file that I put together, and now with your latest demo everything appears to be working on a clean Windows 10 install with Office 64-bit.

    So I think we now have 2 great options for automating 64-bit Office from our 32-bit VB6 apps thanks to you and Olaf! Thanks to you both!

  26. #26

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    1,279

    Re: [RESOLVED] Looking for advice on 64-Bit COM

    Looks like there is one entry missing from Olaf's manifest and qvb6's registry file - probably something introduced in a more recent version than Olaf had available (Redemption.SafeExplorer). Here it is in case anyone needs it:

    Manifest:
    Code:
       <comClass clsid="{c3b05695-ae2c-4fd5-a191-2e4c782c03e0}" threadingModel="Apartment" progid="Redemption.SafeExplorer" />
    Reg:
    Code:
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{c3b05695-ae2c-4fd5-a191-2e4c782c03e0}]
    "AppID"="{9F2804F5-ECAB-4fd7-95B2-2914B8F5A5D8}"

  27. #27

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    1,279

    Re: [RESOLVED] Looking for advice on 64-Bit COM

    Just following up on this thread as I recently encountered some notable events.

    First, I started with Olaf's VBScript approach. I dynamically generate a .VBS file that looks an awful lot like my original VB6 code. I tried running the generated script from Windows Explorer to prove that it could work and everything went great.

    From there, I tried using an old stock function of mine to execute a file using the CreateProcess API (in this case against cscript.exe) and it failed.
    So I tried the same function against wscript.exe and it failed too. Made sure I had the full (and correct) 64-bit system32 path in front of my cscript.exe/wscript.exe calls and it still failed.

    So a mystery! Well, it worked when I double-clicked the script in Explorer, so maybe I should try ShellExecute/ShellExecuteEx. Both failed. ***?

    Turns out that when you try to use the "System32" folder from a 32-bit process on 64-bit Windows, it will redirect you to SysWow64 (and yes, before Dilettante show's up and says "what did you expect you numbskull, we knew this 15 years ago" - I was aware of redirects in the write direction against protected folders, this is the first time I experienced a problem in the "read/execute" direction...I haven't mucked about with protected folders in ages, so this one took me longer to figure out that I would have expected).

    Anyway, after a long story here's the solution to getting to the 64-bit version of cscript/wscript (or any other file in the 64-bit %winsys% folder):

    You can either try using the Wow64DisableWow64FsRedirection API function, or make sure you use the %windir%\SysNative folder instead of anything that resolves to what you think would be the 64-bit system folder. Hope that saves someone a bit of time!

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width