Перейти к содержимому

Фотография

Writing a dll in c# | Anyone know coding | Seeking advice


  • Пожалуйста, авторизуйтесь, чтобы ответить
15 ответов в этой теме

#1
Morbane

Morbane
  • Members
  • 1 883 сообщений
G'day

I am familiar enough with C++ to attempt what I am trying to do - but all of the info I have found so far on dll's - at least as far as the NWN2 toolset goes - is either too complicated to sift out what I really need to do or is only available in de-compiled C# - just different enough that I haven't been able to yank out the core code I need.

The goal: A plugin that enables a one-click save button - essentially what ctrl-s does - simple, yes? no?

I'm not really sure where to start but so far I think my compiler will link the dll project to NWN2Toolset for me - but with no working example I'n not sure its that simple.

I am hoping someone has some advice or some links or even some basic C++ code to get me started. WinAPI is not too far a stretch if needed - for the actual button I suppose.

I wish I could be more specific in my request but this is a general appeal for help so far. Any help is welcome.

:D

Сообщение изменено: Morbane, 04 Сентябрь 2012 - 09:01 .


#2
MasterChanger

MasterChanger
  • Members
  • 686 сообщений
I'd love it if there were one of these for NWNX4 as well (NWNX also uses DLLs) ! Both the toolset and NWX use the concept of plugins. Both could also benefit from more educated community members who can contribute!

I have some C++ background but not enough to just figure things out by wading through the code without a guide. I expect that there are others in my situation and Morbane's.

#3
slowdive.fan

slowdive.fan
  • Members
  • 235 сообщений
Plugin tutorial

Сообщение изменено: slowdive.fan, 27 Август 2012 - 09:30 .


#4
Morbane

Morbane
  • Members
  • 1 883 сообщений
Thanks slowdive - tbh I didnt think anything was out there - imagine it was made and listed 6 years ago - no wonder google didnt find it...
Now I have to learn C# and find a way to re-install visual studio since I have dl'd it already and for some reason it expired (I didnt think it would when I got it).
Really... how different can C# be from C++? They're both based on C arent they? Maybe during the process I'll be able to find the similarities and do it in C++... ok really why would I program the simple tool I'm trying make twice?

=]

#5
slowdive.fan

slowdive.fan
  • Members
  • 235 сообщений
C# is easier than c++ according to most people...I don't remember much from my c++ class in college, but I have been learning c# and I am working on a 2d RPG engine and toolset called openForgeRPG...initial alpha version is complete...now to build on that...

#6
Morbane

Morbane
  • Members
  • 1 883 сообщений
Ahem... I didn't have MSVS C#. But I got the old MSVS C++ verified...lol

So now I have to wait until early tomorrow to dl C#... :(

#7
Morbane

Morbane
  • Members
  • 1 883 сообщений
 I have a class going for my plugin in that class there is a process(?):

private void HandlePluginLaunch(object sender, EventArgs e)       
{
            /*Add the toolbars*/           
List<SaveButton.ToolBarDef> toolBars = myTests.GetAllToolBars();           
for (int j = 0; j < toolBars.Count; ++j)           
{               
for (int i = 0; i < NWN2Toolset.NWN2ToolsetMainForm.App.Controls.Count; ++i)               
{                   
if (NWN2Toolset.NWN2ToolsetMainForm.App.Controls[i].GetType() == typeof(ToolBarContainer))                   
{                       
ToolBarContainer tbc = (ToolBarContainer)NWN2Toolset.NWN2ToolsetMainForm.App.Controls[i];                        if (tbc.Name == toolBars[j].NWNToolsetDockName)                       
{                           
tbc.Controls.Add(toolBars[j].toolBar);                           
break;                       
                   
}               
}           
}       
}

Where or how can I reference the proper Reference to "GetAllToolbars()"?

I'm just trying to get a skeleton to build. There must be a Public class present in NWN2 that needs to be referenced?

Or... Just what to do to get my dll to build? (C# MSVS)

:crying:

Сообщение изменено: Morbane, 03 Сентябрь 2012 - 10:43 .


#8
Morbane

Morbane
  • Members
  • 1 883 сообщений
So now I have the following - I was getting a dirty exception but in the below code the exception is being caught - avoiding a crash. Advice is welcome

private List<ToolBarDef> GetAllToolbars()
{
List<SaveButton.ToolBarDef> list = new List<ToolBarDef>();
foreach (ToolBarDef def in this.AllToolbars.Values)
{
list.Add(def);
}
return list;
}
private void HandlePluginLaunch(object sender, EventArgs e)
{
try
{
/*Add the toolbars*/
List<SaveButton.ToolBarDef> toolBars = myTests.GetAllToolbars();
for (int j = 0; j < toolBars.Count; ++j)
{
for (int i = 0; i < NWN2Toolset.NWN2ToolsetMainForm.App.Controls.Count; ++i)
{
if (NWN2Toolset.NWN2ToolsetMainForm.App.Controls[i].GetType() == typeof(ToolBarContainer))
{
ToolBarContainer tbc = (ToolBarContainer)NWN2Toolset.NWN2ToolsetMainForm.App.Controls[i];
if (tbc.Name == toolBars[j].NWNToolsetDockName)
{
tbc.Controls.Add(toolBars[j].toolBar);
break;
}
}
}
}
}
catch (Exception exception)
{
System.Windows.Forms.MessageBox.Show(exception.Message);
}
}

#9
Morbane

Morbane
  • Members
  • 1 883 сообщений
Most of the above was sifted out from the demo slowdive linked

this:
tbc.Controls.Add(toolBars[j].toolBar);

... is the line causing the exception

I have tried a few different approaches and have managed to get a pop-up to appear with the text I specify, but that is about all I have managed to get so far.

...so I will update as I figure things out

#10
Lance Botelle

Lance Botelle
  • Members
  • 1 480 сообщений
Hi All,

I have just started to get to grips with this side of the game/creation as well. I found these videos helpful. (You can get the first lot free.) : http://www.learnvisu...lute_beginners/

It helped me try to understand the comparison between what I already know (reasonable) like NWN Script and C#, which I have not tried before.

I also found Marshalls PW information useful at his site: http://www.nwn2legends.com/downloads/

Hopefully, we all might be able to get to grips with more as we work on plugins at the same time. I can't say how long I will stick at it, but I am quite keen at the moment, seeing how much time and useful information I can gain from trying.

Lance.

#11
Morbane

Morbane
  • Members
  • 1 883 сообщений
,net Reflector 7.6

a huge help in learning through example - Reflector will basically make any .dll code available for viewing, simply - without a decompiler - at least in the traditional sense of decompiling afaik.

#12
MasterChanger

MasterChanger
  • Members
  • 686 сообщений
I'm very curious to read what you find out. My understanding is that writing toolset plugins in C# would be a bit different from writing plugins for NWNX with C++ but it would still be interesting to hear about your progress.

#13
Morbane

Morbane
  • Members
  • 1 883 сообщений

MasterChanger wrote...

I'd love it if there were one of these for NWNX4 as well (NWNX also uses DLLs) ! Both the toolset and NWX use the concept of plugins. Both could also benefit from more educated community members who can contribute!

I have some C++ background but not enough to just figure things out by wading through the code without a guide. I expect that there are others in my situation and Morbane's.


I am in the same boat MC - I have C++ knowledge but not to the extent that it would quickly translate into C# - even with net.reflector.

TBH, I haven't been on it much lately, but I mean to eventually.

#14
MasterChanger

MasterChanger
  • Members
  • 686 сообщений
Morbane, where did you download the .NET Reflector? Most of the download links I've found have seemed a bit... suspicious.

#15
Morbane

Morbane
  • Members
  • 1 883 сообщений
sorry MC - i havent been watching

ill dropbox the exe and post the link

#16
Morbane

Morbane
  • Members
  • 1 883 сообщений
https://www.dropbox....r_7.6.0.808.exe