C#外部库(LUA)调用的问题 [英] C# external library (Lua) call problem

查看:284
本文介绍了C#外部库(LUA)调用的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的C#(VS2010)。NET(4.0)节目,我遇到我不能由我自己解决,因为有些日子了。

I'm new to programming in C# (VS2010) .Net (4.0) and I'm encountering I couldn't solve by myself since some days already.

我在我的C#code。使用外部脚本语言(LUA)。

I'm using an external scripting language (Lua) in my C# code.

要做到这一点我使用内置的.NET 4.0中LuaInter preTER

To do so I use LuaInterpreter built for .Net 4.0

第一次尝试: 该项目是一个控制台应用程序 - >程序工作正常,当我尝试调用一个Lua类

First try: The project is a console application -> the program works fine when I try to call a Lua class.

第二个尝试: 该项目是一个类Librrary COM使用从Excel - >类库编译罚款,我的用户自定义函数很好地工作在Excel中。但是,当我尝试调用一个Lua类坠毁说,Lua的组件丢失。

Second try: The project is a class Librrary COM used from Excel -> The class library compile fine and my user defined functions work fine within Excel. But when I try to call a Lua class it crashed saying that the Lua assembly is missing.

Could not load file or assembly 'lua51, Version=0.0.0.0, Culture=neutral, PublicKeyToken=1e1fb15b02227b8a' or one of its dependencies. Strong name validation failed. (Exception from HRESULT: 0x8013141A)

要重现该问题:

1,你需要找到LuaInterface .NET 4.0中的 HTTP://www.mdome。组织/ 2011/05/16 / luainterface换CSHARP网 - 4 - 自定义生成/

1- You need to get LuaInterface .Net 4.0 from http://www.mdome.org/2011/05/16/luainterface-for-csharp-net-4-custom-build/

2 - 添加LuaInterface在您的项目中引用

2- Add LuaInterface as a reference in your project

3复制Lua51 DLL的建设目录(我把我的Excel工作表中有太多)

3- Copy the Lua51 DLL in the building directory (I put my Excel sheet there too)

4-复制code的类库

4- Copy the code for the Class Library

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using Excel = Microsoft.Office.Interop.Excel;
using LuaInterface;

namespace POC
{
    [ClassInterface(ClassInterfaceType.AutoDual)]
    [ComVisible(true)]
    public class Functions
    {
        public int test()
        {
            Lua lua = new Lua();
            return 0;
        }

        #region Class in Excel
        [ComRegisterFunctionAttribute]
        public static void RegisterFunction(Type type)
        {
            Registry.ClassesRoot.CreateSubKey(
              GetSubKeyName(type, "Programmable"));
            RegistryKey key = Registry.ClassesRoot.OpenSubKey(
              GetSubKeyName(type, "InprocServer32"), true);
            key.SetValue("",
              System.Environment.SystemDirectory + @"\mscoree.dll",
              RegistryValueKind.String);
        }

        [ComUnregisterFunctionAttribute]
        public static void UnregisterFunction(Type type)
        {
            Registry.ClassesRoot.DeleteSubKey(
              GetSubKeyName(type, "Programmable"), false);
        }

        private static string GetSubKeyName(Type type,
          string subKeyName)
        {
            System.Text.StringBuilder s =
              new System.Text.StringBuilder();
            s.Append(@"CLSID\{");
            s.Append(type.GUID.ToString().ToUpper());
            s.Append(@"}\");
            s.Append(subKeyName);
            return s.ToString();
        }
        #endregion
    }
}

这坠毁的功能是从Excel调用时的测试功能

The function that crashed is the test function when called from Excel

我会采取任何帮助 谢谢

I would take any help on that Thanks

推荐答案

我有很多与.NET,LuaInterface和Lua5.1 interracting在64位机器的问题。 Lua5.1只汇编的32位,这需要你(我相信)建立LuaInterface项目为32位和。尝试改变项目 - >属性 - >构建 - >平台目标到你的.NET项目中的x86。

I've had lots of issues with .NET, LuaInterface, and Lua5.1 interracting on 64-bit machines. Lua5.1 only compiles 32-bit and this requires you to (I believe) build the LuaInterface project as 32-bit as well. Try changing "Project -> Properties -> Build -> Platform Target" to "x86" in your .NET projects.

这篇关于C#外部库(LUA)调用的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆