+ Reply to Thread
Results 1 to 36 of 36

calling DLL

  1. #1
    Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    2007, 2010, 2016
    Posts
    275

    calling DLL

    Hi Guys,

    I have a simpleCalc dll that I want to call. The dll was compiled in C#.

    DLL Code:
    Please Login or Register  to view this content.
    Then I am trying to reference it in VBA:

    Please Login or Register  to view this content.
    But it errors on objCalc.setNumberOne = 3, saying object doesnt support this property or method.

    Any advice please
    Last edited by Jacques Grobler; 01-03-2012 at 03:06 AM.
    Jacques


  2. #2
    Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    2007, 2010, 2016
    Posts
    275

    Re: calling DLL

    Any of the clever people out there to help please...

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,419

    Re: calling DLL

    Did you include a reference to the dll via VBE menu Tools > References?
    Cheers
    Andy
    www.andypope.info

  4. #4
    Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    2007, 2010, 2016
    Posts
    275

    Re: calling DLL

    Hi Andy,

    Yes I have included the reference

  5. #5
    Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    2007, 2010, 2016
    Posts
    275

    Re: calling DLL

    Just to bump it up to the top again... :D

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,419

    Re: calling DLL

    You would have had a much speedy solution if you had included a link to the article where the example came from.
    http://www.geeksengine.com/article/create-dll.html

    You will see that you did not follow the example fully. SetNumberOne and Two are in effect sub routines and not properties. The method of calling them is not via assignment as you have but by passing them as arguments as per the example.

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    2007, 2010, 2016
    Posts
    275

    Re: calling DLL

    Hi Andy,

    Best for the new year

    Thanks for the help, yip, might not have had a problem if I just read properly, but thanks anyway.

  8. #8
    Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    2007, 2010, 2016
    Posts
    275

    Re: calling DLL

    Hi guys,

    I'm not usre if I should call this one solved. I have written a basic add function in VB.Net and exported it to a DLL that is COM visible.
    I have referenced the dll in vba, however I'm not sure of how to use it in vba.

    The dll name is myCOMClassDLL
    The class name is myFunctionsCass
    And the rest is as below:

    Below is the .Net code:
    Please Login or Register  to view this content.
    and below is the vba code:
    Please Login or Register  to view this content.
    In declaring the new class, I'm not sure what must go where. If someone can please help me out on this...

    Tx in advance

  9. #9
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: calling DLL

    Can't see the Namespace there but I think it would be

    Please Login or Register  to view this content.
    You haven't said what is happening with the current code.
    Good luck.

  10. #10
    Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    2007, 2010, 2016
    Posts
    275

    Re: calling DLL

    Hi,

    Why do I need NameSpace in vb.net?

    It gives me an error on the "set" line

  11. #11
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: calling DLL

    In VBA instead of
    Please Login or Register  to view this content.
    I'd write:

    Please Login or Register  to view this content.



  12. #12
    Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    2007, 2010, 2016
    Posts
    275

    Re: calling DLL

    Hi snb,

    The myAddValues function is based in the VB.Net class file, not in vba.

    Do I apply your change to the .net file?

  13. #13
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: calling DLL

    I think you should use Namespaces in all .Net languages.

    Anyway, what error are you getting? (I assume you registered your dll for COM interop?)

  14. #14
    Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    2007, 2010, 2016
    Posts
    275

    Re: calling DLL

    I get:

    Run-time error '429':

    ActiveX component can't creat object

    And yes, my DLL is COM registered

  15. #15
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: calling DLL

    Then the error is in your dll code.

  16. #16
    Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    2007, 2010, 2016
    Posts
    275

    Re: calling DLL

    Can you see in what is above what the problem is?

  17. #17
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: calling DLL

    Couple of questions:
    1. Is that the entire code of your dll?
    2. Are you using this on the same machine where you built and registered the dll?
    3. How exactly did you register it?

  18. #18
    Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    2007, 2010, 2016
    Posts
    275

    Re: calling DLL

    Thanks, I'll go throught the code again and try to see what I have done wrong

  19. #19
    Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    2007, 2010, 2016
    Posts
    275

    Re: calling DLL

    1. Yes that is all the code
    2. No, it is not on the same machine, will try to use it on the same machine
    3. In .Net, you select the registry tick box as well as the COM affiliation box, build the solution and then go to vba and go tools->reference-> reference the .tlb file.

  20. #20
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: calling DLL

    If it is not the same machine, did you register it on the machine you are using it on using regasm?

  21. #21
    Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    2007, 2010, 2016
    Posts
    275

    Re: calling DLL

    What is regasm?

  22. #22
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: calling DLL

    It's the .Net assembly registration program.
    Did it work on the machine where you built it?

  23. #23
    Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    2007, 2010, 2016
    Posts
    275

    Re: calling DLL

    Hi guys,

    I have gone back and forth with this one, I did a tutorial done in C# to create a DLL and call it in VBA and it worked, but now I cannot seem to get it right with VB.Net and I cannot find out why.

    Is there a very good reference to a tutorial for VB.Net to help me solve my problem?

    Thanks in advance.

  24. #24
    Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    2007, 2010, 2016
    Posts
    275

    Re: calling DLL

    Any of the informed people out there?

  25. #25
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: calling DLL

    Have you looked at MSDN? (make sure you are looking at the right version of VS)

    Also you never answered whether it worked on the build machine?

  26. #26
    Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    2007, 2010, 2016
    Posts
    275

    Re: calling DLL

    No it doesnt work on the local machine, and I'm not sure if I did the regasm correct. Did some searches on that as well and will see if I can get to the bottom of this.

    I am programming for Excel and Solidworks, both using vba and it is frustrating because I have to copy code all the time in stead of writing once and reference from both, so I need to get this sorted now.

  27. #27
    Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    2007, 2010, 2016
    Posts
    275

    Re: calling DLL

    Sorry, by local I meant the machine it was created on...

    The reason I think my regasm was inccorect is I never used command line regasm.exe.

    C# has this sort og built into the programme, whereas .net is a seperate process.

  28. #28
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: calling DLL

    C# is a .Net language. When you build the dll, the regasm business is done automatically on that machine.

  29. #29
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: calling DLL

    Perhaps you could zip your project files and post them here for testing? Also tell us which version of VS you are using.

  30. #30
    Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    2007, 2010, 2016
    Posts
    275

    Re: calling DLL

    Ok, so for future reference, if I use the dll on another machine, I must use regasm to reg the applicable dll to the new machine?

  31. #31
    Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    2007, 2010, 2016
    Posts
    275

    Re: calling DLL

    Right, so I have now managed to create a DLL on one machine and implement it on the same machine, using all its functions and availabilities...

    But how would I then register it on a second machine using regasm?

  32. #32
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: calling DLL

    Do you not have the option to create an installer?

  33. #33
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: calling DLL

    Do you not have the option to create an installer?

  34. #34
    Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    2007, 2010, 2016
    Posts
    275

    Re: calling DLL

    What do you mean by create an installer?

  35. #35
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: calling DLL

    Firstly, it appears I may have been incorrect before and you may be able to simply use regsvr32 on the target machine, once your dll is properly compiled and set up for COM.

    In VS you have the option to create a setup and deployment project. I confess I have never used it myself (as I only build things for my own use) but there is a walkthrough here that may assist you.

  36. #36
    Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    2007, 2010, 2016
    Posts
    275

    Re: calling DLL

    Thanks,

    I'll have a look at the website.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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