How to load .dll files in C# from Visual Studio (Working on FANUC FOCAS library)

0

I am working on a project to make a client program to connect CNC FANUC machine with a personal computer and collect several data using FOCAS library.

After downloading FOCAS library with several dll files and a focas library C# file, I tried to create a program to get the data from the machine based on the instruction of functions in FOCAS library (https://www.inventcom.net/fanuc-focas-library/general/fwlib32).

However, whenever I execute the program, I always face the error saying that "Unhandled exception. System.DllNotFoundException: Unable to load DLL 'FOCAS32.dll' or one of its dependencies(0x8007007E)". I searched on the Google and stackoverflow questions list but nothing has been working.

Could you tell me how to solve this problem?

To elaborate the situation, I made a solution called "FanucCNCDataAcquisition.sln" by using Visual Studio 2019 and I stored two projects: one is FOCASLibrary which has a Focas32.cs for the library purpose and the other is DataAcquisition which has a program.cs for execution with the reference on the focas library. I downloaded several .dll files including FOCAS32.dll and those are not in the same directory with the solution so I am curious if the cause of the problem is based on the location of the files.

c#
visual-studio-2019
dllimport
cnc
asked on Stack Overflow Mar 9, 2021 by sol

1 Answer

0

You need to reference the DLL within the solution, i'll show you in the steps below: (My visual studio is in Portuguese but you can follow these steps with English) First, you right-click on "References" and click "Add Reference" enter image description here

In this window you are going to click "Search" and add your DLL manually enter image description here After that, all the classes and methods within this library will be available for you to use, you just go to the oficial documentation and look for code examples.

answered on Stack Overflow Mar 9, 2021 by Gabriel Manzini

User contributions licensed under CC BY-SA 3.0