Skip to content
⌘ NSIS Forum Archive

Error calling .NET DLL method

5 posts

Barchen#

Error calling .NET DLL method

I have a problem.
during setup.
---------------------------

---------------------------
Error calling .NET DLL method

Constructor on type 'WordLauncher.Launcher' not found.
---------------------------
ОК
---------------------------

from nsi:
File "WordLauncher.dll" 
StrCpy $0 "Hello, Signatec" 
DetailPrint $0 CLR::Call /NOUNLOAD "WordLauncher.dll" "WordLauncher.Launcher" "launch" 1 "some string value" 
from dll:

using System.Reflection;
using Microsoft.Office.Interop.Word;
namespace WordLauncher
{
    public static class Launcher
    {
        static object missing = Missing.Value;
        
        public static void launch(string text)
        {
          
            Application Word_App = null;
            Document Word_doc = null;
            try
            {
                Word_App = new Application();
                Word_doc = new Document();
            }
            catch
            {
            }
            AutoCorrect autocorrect = Word_App.AutoCorrect;
            AutoCorrectEntries autoEntries = autocorrect.Entries;
            autoEntries.Add("Inntroduction", "Introduction");
            Documents Docs = Word_App.Documents;
            Word_App.Visible = true;
            _Document my_Doc = (_Document)Word_doc;
            Word_doc = Docs.Add(ref missing, ref missing, ref missing, ref missing);
            object start = 0;
            object end = 0;
            Range range = Word_doc.Range(ref missing, ref missing);
            range.Text = text;
        }
    } 
Barchen#
Originally posted by claesabrandt
You are missing a public constructor in your .NET class.
Class is static.
claesabrandt#
Hmm, okay. I never tested it with static classes. The thing is that I create an instance of the class when attempting to call the method. A quick remedy right now would be to create a default constructor in your class that does nothing.
claesabrandt#
Ups, can't have constructors in static classes. Only remedy right now would be to make the class non-static.