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();
}
}
}