首页 \ 问答 \ asp.net (vb.net)怎样调用Module文件?

asp.net (vb.net)怎样调用Module文件?

asp.net (vb.net)怎样使用Module文件?像写WINFORM一样,用到一些全局变更及自定义函数
更新时间:2019-05-30 08:52

最满意答案

直接去添加引用~然后去调用就可以了

其他回答

用 com 当然可以。不过,com 封装比较复杂,不太熟悉的话,出错调试很麻烦。而且要求的知识面较宽。

简单的封装可以这样实现:
1)通过 vs 创建一个 clr 类库项目,在其中可以简单封装标准的 dll 导出函数,当然,这些导出函数实际上是不导出。然后定义一个 .net 类,在这个类中定义对应所有导出函数的公共方法,然后在公共方法内部调用这些标准的 c++ 函数。生成这个 clr dll。
2)在vb中,可以引入这个 clr dll,然后 vb 就可以通过调用 clr dll 中定义的 .net 类来间接调用原来标准的 c++ dll 导出函数了。

当然,因为在.net 中,所有的实现都是通过类来封装的,强调的是面向对象的编程理念。因此,可以将 c++ dll 本来的导出函数封装成类。然后实例化一个全局 c++ 类,在后续定义的.net 类中,定义相关的公共方法,私有方法,在内部对这个全局的 c++ 类进行操作(这一切都是在同一个.cpp文件中就可以完成的,利用 cl 编译器的混编特性进行编译)。在客户程序,唯一要做的就是调用公共方法就 ok 了。

以下提供示例,楼主可以参考一下:
// clr 类库项目。
// nestedcppclassdll.cpp 
///////////////////////////////
// 非托管代码。
#pragma unmanaged
#pragma once

#include 

 
#include 
 
  

class nestedcppclass {
public:
 void printinfo() {
  printf("nestedcppclass\r\n");
 }

 int func(int i) {
  return ++i;
 }
};

nestedcppclass g_ncc;

#pragma managed
///////////////////////////////

///////////////////////////////
// 托管代码。
using namespace system;

namespace nestedcppclassdll {

 public ref class outclrclass
 {
 public:
  void printinfo() {
   console::writeline("outclrclass");
   g_ncc.printinfo();
  }

  int func(int i) {
   return g_ncc.func(i);
  }
 };
}
///////////////////////////////

'vb控制台项目。
'项目需要引入clr dll
'module1.vb
module module1
    sub main()
        dim c as nestedcppclassdll.outclrclass
        c = new nestedcppclassdll.outclrclass
        c.printinfo()
        system.console.writeline(c.func(1))
    end sub
end module

'控制台输出内容:
'outclrclass
'nestedcppclass
'2

// c#控制台项目。
// 项目需要引入 clr dll。
// program.cs 
///////////////////////////////

using system;
using nestedcppclassdll;

namespace nestedcppclassapp
{
    class program
    {
        static void main(string[] args)
        {
            outclrclass c = new outclrclass();
            c.printinfo();
            console.write(c.func(1));
        }
    }
}

//控制台输出内容:
//outclrclass
//nestedcppclass
//2
 

相关问答

更多

相关文章

更多

最新问答

更多
  • 在csproj中使用appdata环境变量(Use appdata environment variable in csproj)
  • 从背景返回后,Skobbler Map崩溃(Skobbler Map crashes after returning from background)
  • 如何保持对绑定服务的轮询?(How to keep polling a bound service?)
  • ASP.NET单选按钮jQuery处理(ASP.NET radio button jQuery handling)
  • Linux上的FORTRAN图形库(FORTRAN graphic library on Linux)
  • 我们如何根据索引更新dynamodb表(不基于primary has和range key)(how can we update dynamodb table based on index(not based on primary has and range key))
  • 功能包装避免重复(wrap of functions avoid duplicating)
  • Android BroadcastReceiver和Activity.onPause()(Android BroadcastReceiver and Activity.onPause())
  • 无法使用phonegap 2.4在Android上播放录音(unable to play audio recordings on android using phonegap 2.4)
  • VS2015 + Resharper:不要使用C#6(VS2015 + Resharper: Don't use C#6)
  • 大学电脑四级对初学者来说要多久能过
  • 特殊字符删除?(Special characters remove?)
  • Android视频教程现在网上的都比较零散呢?有些太坑爹了,感觉老师就是在想当然的讲
  • 计算同一个表中不同行之间的差异[重复](Calculate delta's between different rows in same table [duplicate])
  • Javaweb开发,技术路线是什么?该怎么写?
  • JavaScript只在php代码中执行一次(JavaScript only executes once inside php code)
  • 不兼容的字符编码:ASCII-8BIT和UTF-8(incompatible character encodings: ASCII-8BIT and UTF-8)
  • Clojure(加载文件)给出错误(Clojure (load-file) gives an error)
  • 为具有瞬态scala依赖性的spring-xd项目优化gradle(Optimize gradle for spring-xd project with transient scala dependency)
  • 如何才能在Alpha测试模式下发布我的应用程序?(How can I publish my app in Alpha test mode only?)
  • “没有为此目标安装系统映像”Xamarin AVD Manager(“No system images installed for this target” Xamarin AVD Manager)
  • maven中的Scalatest:JUnit结果(Scalatest in maven: JUnit results)
  • 使用android SDK将文件直接上传到存储桶中的文件夹(Upload a file directly to a folder in bucket using android SDK)
  • 是否应将plists导入CoreData?(Should plists be imported to CoreData?)
  • java.lang.reflect.InvocationTargetException JavaFX TableView(java.lang.reflect.InvocationTargetException JavaFX TableView)
  • 根据唯一列值动态创建多个子集(Dynamically create multiple subsets based on unique column values)
  • 使用CSS可以使HTML锚标签不可点击/可链接吗?(Is it possible to make an HTML anchor tag not clickable/linkable using CSS?)
  • 嵌套的模板可能性(Nested template possibilities)
  • 任何方式在iOS7 +上以编程方式打开蓝牙(Any way to turn on bluetooth programmatically on iOS7+)
  • 如何为给定的SQL查询编写JPA查询(How I can write JPA query for given SQL query)