+ Reply to Thread
Results 1 to 30 of 30

C# DLL Calling From Excel 32 Bit Vs 64 Bit

  1. #1
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    C# DLL Calling From Excel 32 Bit Vs 64 Bit

    Hi,

    I have a very simple addition DLL.

    In the VBE > Tools > References I add the .tbl File.

    Below is the code that I use

    Please Login or Register  to view this content.
    The Code runs fine on a 32 Bit Excel version, but errors out on 64 Bit.

    1 observation though, even though the Code errors out on the 64 Bit, the Intellisense (DLLs Methods) are available at design time.



    Can anyone help me with this??

    Cheers!

    Deep
    Attached Images Attached Images
    Last edited by NeedForExcel; 04-25-2018 at 05:47 AM.
    Cheers!
    Deep Dave

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: C# DLL Calling From Excel 32 Bit Vs 64 Bit


  3. #3
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: C# DLL Calling From Excel 32 Bit Vs 64 Bit

    Quote Originally Posted by Marc L View Post
    Hi,

    Thank you for the reply. I have already been though the documentation before posting. Unfortunately still haven't gotten it to work

    I have been through a few links online, but none seem to get me code working.

  4. #4
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: C# DLL Calling From Excel 32 Bit Vs 64 Bit

    As far as I am aware you will need to compile a 64bit version of your dll.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  5. #5
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: C# DLL Calling From Excel 32 Bit Vs 64 Bit

    Quote Originally Posted by xlnitwit View Post
    As far as I am aware you will need to compile a 64bit version of your dll.
    Hi.

    Thank you for the reply.

    Can you share me some sort of documentation which shows what exactly needs to be done. I will need to share it with the guy who has made the DLL?

    Cheers

  6. #6
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: C# DLL Calling From Excel 32 Bit Vs 64 Bit

    I would think he should know how to do that. If using visual studio you just select the target platform when building the dll.

  7. #7
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: C# DLL Calling From Excel 32 Bit Vs 64 Bit

    Hi,

    The communication from the guy who made the dll says that the Target Platform is set to "Any CPU" which should work on both.

    However, to try it out, we built the dll again with Target Platform set to x64. It still does not work.

    Ref Link we used - https://msdn.microsoft.com/en-us/library/ms185328.aspx

  8. #8
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: C# DLL Calling From Excel 32 Bit Vs 64 Bit

    This is not really a VBA issue, and without the code for the dll I couldn't really comment as to why it doesn't work on 64 bit.

  9. #9
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: C# DLL Calling From Excel 32 Bit Vs 64 Bit

    Here is the DLL Code as required -

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Runtime.InteropServices;

    namespace Calculation
    {



    [Serializable(), ClassInterface(ClassInterfaceType.AutoDual), ComVisible(true)]
    public class Main
    {
    public calculate Sum_num()
    {
    return new calculate();
    }
    }

    [Serializable(), ClassInterface(ClassInterfaceType.AutoDual), ComVisible(true)]
    public class calculate
    {
    public double Add(double a , double b)
    {
    return a + b;
    }
    }



    }

  10. #10
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: C# DLL Calling From Excel 32 Bit Vs 64 Bit

    It works fine here for 64 bit. Are you sure you set the build options properly for Release, not Debug?

  11. #11
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: C# DLL Calling From Excel 32 Bit Vs 64 Bit

    Yes, we have set it for Release and not debug.

    Is there a possibility you can share the dll made by you which is working at your end? Since we know it works on 64 Bit on your PC. If it does not work on mine, we can be certain there is some other issue.

    Cheers!

  12. #12
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: C# DLL Calling From Excel 32 Bit Vs 64 Bit

    Here it is.
    Attached Files Attached Files

  13. #13
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: C# DLL Calling From Excel 32 Bit Vs 64 Bit

    Hi,

    Thank you for the reply. The dll shared by you isnt working at my end. I am getting the same error I was getting previously.

    I tried it on another PC that has 64 Bit Excel, but it isn't working there as well.

    Do you think there can be an issue with 32Bit Windows Vs 64 Bit Windows??

    Cheers!
    Last edited by NeedForExcel; 04-27-2018 at 02:47 AM.

  14. #14
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: C# DLL Calling From Excel 32 Bit Vs 64 Bit

    Did you register the dll successfully? Did Calculation appear in the reference list, or did you have to browse to the dll?

    I don’t see how the bitness of windows could be relevant since we both must be running 64 bit.

  15. #15
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: C# DLL Calling From Excel 32 Bit Vs 64 Bit

    Yes.. From the VBE > Tools > Reference, I set a reference to the tlb file.

    I was even able to access the intellisense from the dll.

    But after running the code, I get an error 429 - ActiveX component can't create object

  16. #16
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: C# DLL Calling From Excel 32 Bit Vs 64 Bit

    Just to confirm- you could see Calculation already in the list of available references, and you did not have to browse to the actual file?

    Which version of Windows are you using?

  17. #17
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: C# DLL Calling From Excel 32 Bit Vs 64 Bit

    I was able to see Calculation already in the list of available references, but I put your DLL & TLB in a different folder to avoid any confusion. Then I browsed to that folder again and and set the reference.

    I am using Windows 10

  18. #18
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: C# DLL Calling From Excel 32 Bit Vs 64 Bit

    If you already had your Calculation dll installed, I suggest you uninstall it, then install the new dll and select it directly from the references dialog, not by browsing.

  19. #19
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: C# DLL Calling From Excel 32 Bit Vs 64 Bit

    Quote Originally Posted by xlnitwit View Post
    If you already had your Calculation dll installed, I suggest you uninstall it, then install the new dll and select it directly from the references dialog, not by browsing.
    Hi,

    I am not able to understand. How do you uninstall the dll?

    All I did was place my DLL & TLB in 1 folder, and selected the TLB from that path in references.

  20. #20
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: C# DLL Calling From Excel 32 Bit Vs 64 Bit

    You unregister it using whatever you used to register it in the first place (regasm or regsvr presumably).

  21. #21
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: C# DLL Calling From Excel 32 Bit Vs 64 Bit

    Quote Originally Posted by xlnitwit View Post
    You unregister it using whatever you used to register it in the first place (regasm or regsvr presumably).
    OMG, I haven't done any of that.. I did not know you need to register it. Isn't just adding the reference enough?

    On my 32-Bit Excel, I haven't done any of the registration part and it still works..

  22. #22
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: C# DLL Calling From Excel 32 Bit Vs 64 Bit

    Was the dll built on that machine? Or did you run a setup program? I'm not sure how it would appear in the reference list if it had not been registered somehow.

  23. #23
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: C# DLL Calling From Excel 32 Bit Vs 64 Bit

    The DLL was built on a colleagues PC, and was sent to me.

    It would appear in the reference list by clicking the browse button and browsing to that location.

    I have done using this method numerous times previously. I was absolutely not aware that the dll needs to be registered before.
    Last edited by NeedForExcel; 04-27-2018 at 08:06 AM. Reason: Grammar Correction

  24. #24
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: C# DLL Calling From Excel 32 Bit Vs 64 Bit

    I asked previously if you could see it in the list without browsing to the file.

    As far as I know, .Net assemblies should be registered to be used with COM. After downloading the dll I posted earlier to a machine with 32bit Office but 64bit Windows, I confess I can't register it correctly (that may be a permissions issue at work). I can however set a reference to the tlb and see the Intellisense as you can but also get a 429 error when trying to run the code, which is not unexpected for a 64bit dll I think. Trying to set a reference to the dll rather than the tlb fails.

  25. #25
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: C# DLL Calling From Excel 32 Bit Vs 64 Bit

    Alright.. Seems the problem is more complicated than I thought.

    Anyways, I will keep you updated if I find a solution.

    Thank you very much for your time.

    Rep Added for all the help.

    Cheers!
    Deep

  26. #26
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: C# DLL Calling From Excel 32 Bit Vs 64 Bit

    By the way, do you get this error on a 32 Bit Excel?
    Attached Images Attached Images

  27. #27
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: C# DLL Calling From Excel 32 Bit Vs 64 Bit

    No, I just get a 429 error.

    I have just built a 32 bit version on my work computer and it does seem to work without registering it. I will have to check the 64 bit one on another computer when I have access to one.

  28. #28
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: C# DLL Calling From Excel 32 Bit Vs 64 Bit

    I spent over six months trying to find out why I was getting "error 429 - ActiveX component can't create object". I gave up after some time and while searching for other issues on Google, I came across a site about which third parties adds-in work with which version. ActiveX component and most adds-in do not like excel 64 bits. When I changed my excel version in to 32 bits, the code started to work. I also know there are people who can use ActiveX component on 64 bits.

  29. #29
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: C# DLL Calling From Excel 32 Bit Vs 64 Bit

    Hi AB33,

    Thank you for the reply..

    I have both versions 32 & 64 Bit..

    My Code works flawlessly on 32 Bit, but the same code gives me the 429 Error on 64 Bit.

    Its absolutely frustrating..

  30. #30
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: C# DLL Calling From Excel 32 Bit Vs 64 Bit

    Quote Originally Posted by xlnitwit View Post
    No, I just get a 429 error.

    I have just built a 32 bit version on my work computer and it does seem to work without registering it. I will have to check the 64 bit one on another computer when I have access to one.
    No Problem,

    Thank you for the help so far

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Excel calling Outlook
    By Steve105 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-04-2015, 05:12 AM
  2. Calling Excel Gods! Help Needed for Excel Game
    By JonLombardi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-11-2014, 10:54 PM
  3. [SOLVED] help with calling a function (B) and return control of program flow to the calling functio
    By john/nyc in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 10-26-2012, 11:06 AM
  4. Calling word from excel
    By gnome_core in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-20-2009, 12:57 PM
  5. Calling a DLL from Excel.
    By Jim15 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-01-2007, 11:15 AM
  6. Calling a DLL in MS-Excel
    By Jim in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-22-2006, 02:20 AM
  7. Replies: 3
    Last Post: 08-15-2005, 12:05 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1