0

I am trying to add a DLL to Visual Studio 2019 and after enabling CLR I went into the References tab then Add Reference then Browse. Here I found my DLL file and tried adding it, but I get an error saying, "Could not add a reference to "path" as it is not a type or version current project can use." This file is in fact a DLL file but what is wrong? How can I get Visual Studio to accept DLL files?

I would also like to note that I cannot actually leave CLR on when compiling my project in plain C since I get errors. However, I assume I can turn CLR on and then add my reference and then turn CLR off and then compile. But this won't be an issue till I figure out the bug stated in the first paragraph.

  • 1
    What is your goal here? A dll is loaded at runtime. If you wish to use functions from the dll you should link against the import library and then place the dll in the same directory as the executable. – Retired Ninja Apr 03 '23 at 02:03
  • @RetiredNinja I have been trying to use the DLL for a while but every answer I read on this topic suggests I add it to resources before being able to call functions from it. Can you link me something that explains if what I was doing is wrong? – IgnoreExeption Apr 03 '23 at 02:23
  • For C projects, you don't add references to DLLs. You add libraries to your linker dependencies. References to DLLs is a CLR thing. It is for obtaining their CLR metadata. – Raymond Chen Apr 03 '23 at 03:44
  • @RaymondChen Oh that is good to know but all sources I have found told me to link a .lib file which I don't see. – IgnoreExeption Apr 03 '23 at 04:28
  • It should be in the SDK for the DLL you are using. – Raymond Chen Apr 03 '23 at 15:00
  • @RaymondChen I made the DLL myself I have no idea what you are talking about here. – IgnoreExeption Apr 04 '23 at 00:09
  • When you made the DLL, there should have been two outputs: A *.dll file and *.lib file. – Raymond Chen Apr 04 '23 at 00:15
  • @RaymondChen Well I want it to output a DLL but every tutorial I see links to a lib file while also requiring a DLL. I want it to be dynamically loaded but I can't get it to work. Here check this for an updated question https://stackoverflow.com/questions/75924529/how-to-use-a-dll-in-visual-studio-with-a-lib-file?noredirect=1#comment133916911_75924529 – IgnoreExeption Apr 04 '23 at 00:20
  • You need to configure your DLL project to produce both a lib and a dll. – Raymond Chen Apr 04 '23 at 02:33
  • @RaymondChen How do I do that? Also is it correct to link to the .lib file and then only include the .dll file in the same directory that the exe is being launched from? – IgnoreExeption Apr 04 '23 at 04:26

0 Answers0