logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
NWNX4 and .NET

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Development
View previous topic :: View next topic  
Author Message
Undertowe



Joined: 03 Jan 2005
Posts: 33

PostPosted: Thu Aug 21, 2008 1:21    Post subject: NWNX4 and .NET Reply with quote

I've just created a plugin that calls a .NET assembly from NWNX4. It's inspired by a similar plugin for NWNX2 by ronchese:

http://nwnx.org/phpBB2/viewtopic.php?t=1002

Stay tuned...
Back to top
View user's profile Send private message
Undertowe



Joined: 03 Jan 2005
Posts: 33

PostPosted: Fri Aug 22, 2008 7:06    Post subject: Reply with quote

NWNX4 Dot Net 0.0.1 ALPHA
http://www.theheresyproject.com/downloads/NWNX4DotNet/NWNX4DotNet_v0.0.1a.rar

This plugin allows you to call .NET assemblies from NWNX4 and therefore NWN2.

IMPORTANT NOTE: This is my first NWNX4 plugin and my first time using C++ (I mostly do web development in C#). I was flying by the seat of my pants most of the time, so I wouldn't be surprised if I made some stupid mistakes. This plugin should NOT be considered stable or ready for production use. I'm hoping that some of the more experienced plugin developers can offer their guidance and feedback.

Special thanks to ronchese for his NWNX2 Dot Net plugin, which helped me write this one.

Again, I'm a complete novice at plugin development and C++ so your feedback is very much appreciated.

Issues:

  • In order to call a managed assembly from unmanaged code, I had to compile the DLL with CLR support. However, this caused nwserver.exe to crash due to the "mixed DLL loading problem". The solution I found was to create the DLL with no entry point (/NOENTRY). This means that DllMain() never gets called, as it does with most plugins. DllMain() is generally used to instantiate the plugin object and set the plugin path, so I had to do that somewhere else. I chose to instantiate the plugin object from GetPluginPointerV2() and set the plugin path from the plugin constructor. This seems to work fine, but might not be the best solution. I'm open to suggestions.

  • DllMain() is also generally used to delete the reference to the plugin object, thereby triggering the plugin destructor which writes a final "* Plugin unloaded." to the log file. Because DllMain() never gets called, this approach won't work. I couldn't figure out another way for the plugin to be notified when it's being unloaded. Consequently, the plugin reference never gets deleted, the destructor never gets called, and the log file never gets written to. Everything I read about how to work around this problem requires that you make changes to the code that loads the DLL. Can anyone think of a solution that doesn't involved changing the NWNX4 code?

  • The .NET assembly gets loaded into memory every time it gets called. It might be more efficient to keep it in memory, but I haven't tried to do this yet. I'm open to suggestions.

  • I noticed that ronchese's plugin DLL is much smaller than mine (84 KB vs. 1170 KB). Compiling with CLR support adds much to the file size, but AFAIK his DLL is also compiled with CLR support. I tried playing with various compiler options, but I couldn't reduce the file size. Does anyone know why my DLL is so much larger, and how I can reduce the size?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Development All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group