Resolved DLL import

danut1234

New member
Joined
Dec 27, 2020
Messages
4
Programming Experience
1-3
Hi, i want to make a program to control an electronic board. The producer of the electronic board supply a DLL to acces some special functions of the board. But i cant use it, it gives me an error. Here is how a try to use it.
C#:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WindowsFormsApplication5
{
    public partial class Form1 : Form
    {
        [System.Runtime.InteropServices.DllImport("libe1803d.dll")]
        public static extern int E1803_get_library_version();
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
           label1.Text = Convert.ToString(E1803_get_library_version());
        }
    }
}
The E1803_get_library_version() is a function in "libe1803d.dll" i know this from the documentation.
The DLL file is placed in the Debug folder... and in fact i have placed the DLL file everywhere in the project folder, including in windows/system32 folder
I have tried to Add Reference in the project, but i cant, it say that "the file is not accessible or is not a valid assembly or COM component."(something like that...)
I have tried to see the dependency of the DLL file and it say that i am missing some file... after some documentation someone said that the problem is from VC++ redistribution package but i have installed VC++ 2012 (version of my visual studio) VC++ 2015 2017 and 2019.
Here is the error that i get.
Unable to load DLL 'libe1803d.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
Thank you for your Help.
 
Last edited by a moderator:
Solution
After installing VS2017 community, to have v141, i was able to compile the dot net DLL from the example folder... but after all the trouble i could not start the application because the DotNet DLL requests another DLL "dcomp.dll" to work. DCOMP.dll is part of Windows 8, and i have Windows 7. The C++ unamanaged DLL libe1803d.dll needs the same DCOMP.DLL to work, but i just ignored the problem... So, in the end, i need Windows 8....

I ave found the solution here Solution Link

danut1234

New member
Joined
Dec 27, 2020
Messages
4
Programming Experience
1-3
My aplication runs on 32 bit, the DLL file comes in two variants, 32 and 64 bit, i used the 32 bit version of the DLL.

How to Add the DLL file to Solution Explorer? Add reference does not work, i tried to drag and drop it, it doesn't seem to appear any ware and i have the same error.

In the Readme file writes that:
In both cases for proper usage and compilation one of the environment switches ENV_WINDOWS (for all Windows operating systems) or ENV_LINUX
(for all Linux operating systems) has to be defined.

Ho do i "define" the ENV_WINDOWS ?

If it helps i have attached an archive with the DLL and with two examples that the producer supply.
If anyone needs more information i will provide them....
 

Attachments

  • libe1803.zip
    236.1 KB · Views: 12
Last edited:

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
3,381
Location
Chesapeake, VA
Programming Experience
10+

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,917
Location
Sydney, Australia
Programming Experience
10+
How to Add the DLL file to Solution Explorer? Add reference does not work
Of course it doesn't. You're not referencing it. It's just a file and you add it like any other file, which would be by right-clicking the project and selecting Add > Existing Item. Alternatively, you can select Add Existing Item from the Project menu. The point of this exercise would be to simply make sure that the DLL always ends up in the output folder for deployment with your application. You don't have to do it that way but it's a good way to be sure the file is always there without having to think any further about it. If you have to set that environment variable though, it won't matter how you out the file in that folder.
 

JohnH

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
1,197
Location
Norway
Programming Experience
10+
The zip you attached had a "dot net" folder, with a managed C++ library and two C# test projects, it would probably be better to use that from your C# application.
 

danut1234

New member
Joined
Dec 27, 2020
Messages
4
Programming Experience
1-3
The zip you attached had a "dot net" folder, with a managed C++ library and two C# test projects, it would probably be better to use that from your C# application.
How to use them? i don't have much experience with this kind of programing. I usually write microcontroler software...:giggle:
 

JohnH

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
1,197
Location
Norway
Programming Experience
10+
Open the projects in VS and compile them.
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,917
Location
Sydney, Australia
Programming Experience
10+
The managed library can be referenced in your own project. The test projects that @JohnH mentioned will do that and they will show you how to call methods in the managed library.
 

danut1234

New member
Joined
Dec 27, 2020
Messages
4
Programming Experience
1-3
After installing VS2017 community, to have v141, i was able to compile the dot net DLL from the example folder... but after all the trouble i could not start the application because the DotNet DLL requests another DLL "dcomp.dll" to work. DCOMP.dll is part of Windows 8, and i have Windows 7. The C++ unamanaged DLL libe1803d.dll needs the same DCOMP.DLL to work, but i just ignored the problem... So, in the end, i need Windows 8....

I ave found the solution here Solution Link
 
Solution
Top Bottom