How to load DLL using C#? -
i have small dll has 3 functions : init, load , run. i'm new c# read questions here, i've opened console project , wanted load dll , use it's functions. unfortunately - didn't work. can advise went wrong?
this error get:
unable find entry point named 'init' in dll '....path dll....'.
this code:
using system; using system.collections.generic; using system.linq; using system.text; using system.runtime.interopservices; namespace consoleapplication1 { class program { [dllimport("c:\\desktop\\dlltest.dll", charset = charset.unicode)] public static extern bool init(); [dllimport("c:\\desktop\\dlltest.dll", charset = charset.unicode)] public static extern bool load(string file); [dllimport("c:\\desktop\\dlltest.dll", charset = charset.unicode)] public static extern bool play(); static void main() { console.writeline("got till here!!!"); init(); load("c:\\desktop\\the_thing_about_dogs_480x270.mp4"); play(); } }
}
the thing can suspect maybe fact i'm not creating instance? besides that, no clue :(
* editing : * dll :
using system; using system.collections.generic; using system.linq; using system.text; namespace dlltest { public class dlltestapi { myinfo localplay; public bool init() { localplay = new myinfo(); return true; } public bool load(string file) { localplay.load(file); return true; } public bool play() { localplay.startnewthread(); return true; } public bool stop() { localplay.dxstopwmp(); return true; } public bool pause() { localplay.dxpause(); return true; } public bool resume() { localplay.dxresume(); return true; } public bool close() { localplay.dxclose(); return true; } } }
the error message tells problem is. dll not export function named init
. possible reasons include:
- the dll not unmanaged dll.
- the dll not export function of name.
- the dll exports function, name decorated or mangled.
probably easiest way diagnose fault use tool dependency walker inspect dll's exports.
update
from edit question, clear item 1 reason. dll managed dll , incorrect attempt access using p/invoke. add reference console application project.
Comments
Post a Comment