Jump to content

Can my plugin load a c dll with dllimport?


Recommended Posts

I have a C dll that I'm trying to load with my plugin but in the debug console it says DllNotFoundException when it tries to load the dll.

I got the dll working with a C# console application so I'm fairly certain it works.

I put the dll in the same directory as the plugin (I'm using the old plugins directory) and I know the plugin is loading.

Is it possible to load a C dll with a plugin, and if yes, can anyone tell me where it should go or what I'm doing wrong?

Link to comment
Share on other sites

I have a C dll that I'm trying to load with my plugin but in the debug console it says DllNotFoundException when it tries to load the dll.

I got the dll working with a C# console application so I'm fairly certain it works.

I put the dll in the same directory as the plugin (I'm using the old plugins directory) and I know the plugin is loading.

Is it possible to load a C dll with a plugin, and if yes, can anyone tell me where it should go or what I'm doing wrong?

I'm not convinced that it is, given that unity runs Mono, not .net (though they are both c#). Try looking into the mechanism Mono uses to load them.

Link to comment
Share on other sites

I think someone managed to load a c dll in an earlier version of KSP. You could try moving the dll into the root directory of KSP (where KSP.exe is located). For standard .NET/Mono applications that is the location that is searched when trying to use an external dll.

Link to comment
Share on other sites

It is possible to talk to a C DLL from a C# DLL. The modder who did KerbComAvionics did just that (there's a C DLL "lpsolve.dll" included in the package). You can look at the source for that mod to see what you have to do in the C# DLL to load it.

http://forum.kerbalspaceprogram.com/threads/29387-0-21-x-KerbCom-Avionics-0-3-0-6-Alpha-%2829-August%29-now-with-video%21?highlight=kerbcomavionics

You would have to cross compile the C DLL to support multiple platforms (mac / Linux / windows).

Link to comment
Share on other sites

Putting it in the main directory fixed it. I took a look at KerbComAvionics but the source doesn't seem to be updated, I'm guessing if I put my mod in the GameData folder then it might be loadable from there, either that or a relative path.

Thanks everyone.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...