Click here to Skip to main content
15,887,945 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i just try to make a dll from this link, How to create a DLL library in C and then use it with C#[^], it actually works

but then when i try to make a dll link with mysql
i got 'DllNotFoundException was unhandled' error message..

need somebody to help thank you..

What I have tried:

this is the code in my cpp (dll) code

#pragma once
#pragma comment (lib, "libmysql")

#include <iostream>
#include "C:\BookScanner\extension\MySQL-API\include\mysql.h"

MYSQL *__con, *__conString;

extern "C"
{
	__declspec(dllexport) void openConnection(){
		__con = mysql_init(NULL);
		__conString = mysql_real_connect(__con, "localhost", "root", "", "bookbardatabase", 3306, NULL, 0);
		std::cout << __conString ? "successfully connected" : "failed to connect to server";
	}
}


this is the code in c# i used to run my dll file

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

using System.Runtime.InteropServices;

namespace ConsoleApplication1
{
    class Program
    {
        [DllImport("C:\\Users\\user\\Desktop\\MyysqConnector\\Debug\\MyysqConnector.dll")]
        public static extern void DisplayHelloFromDLL();

        static void Main(string[] args)
        {
            DisplayHelloFromDLL();
            Console.ReadLine();
        }
    }
}
Posted
Updated 4-Aug-17 22:35pm
Comments
Mehdi Gholam 5-Aug-17 2:16am    
Make sure the DLL and all dependent DLL files are beside your EXE.
Richard MacCutchan 5-Aug-17 2:57am    
Are you sure the name of the dll is correct? Also, where is the code for DisplayHelloFromDLL?
Richard MacCutchan 5-Aug-17 4:58am    
Quite simply I suggest that MyysqConnector.dll is not the correct spelling of your dll filename.

1 solution

It is abvious that a dll is missing. The most common reason is, that the needed dll isnt installed or isnt in the working directory of the running exe. So look where your exe is and copy the missing dll into the directory.

I like the good old dependency walker for such issues.
 
Share this answer
 
Comments
Richard MacCutchan 5-Aug-17 4:59am    
See my latest comment.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900