vb.net把dll放到程序的Resources资源里面,能直接调用Resources里面的dll吗?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vb.net把dll放到程序的Resources资源里面,能直接调用Resources里面的dll吗?相关的知识,希望对你有一定的参考价值。

vb.net把dll放到程序的Resources资源里面,能直接调用Resources里面的dll吗?
如果能的话,调用代码是什么啊?
补充下,主要是想实现单个exe程序运行,把dll融合到exe程序里边,

dll文件可以直接引用进去啊,你打开引用文件,直接引用进去就好了,是在程序引用里面,本身就融合在exe文件里,何必放在Resource目录下,画蛇添足。
一些特定的文件,如DB格式、Cab格式、图片格式直接放在相对目录下不就好了,不然你要开发一个稍微像样点的软件根本没办法打包给别人,资源包和检测安装包你怎么给别人打包安装嘛?Resource目录是针对ASP.NET WebForm程序,MapPath的方法可以直接取得资源目录。WinForm考虑他的项目移植性,你直接做安装包就好了,安装资源文件到哪个位置应该由客户自己来定。
dll本身就是封装好的代码,可以直接引用编译,不属于资源文件行列。
第三方控件也不是什么耻辱的事情,大部分成功的软件都是自己开发第三方控件,你用微软自带的控件根本满足不了市场需求,仅仅维持一个学习层次。
参考技术A 如果是想为了缩减文件数量,可以考虑用这种方法,另外要配合反射使用。
我觉得这样其实没有必要,多两三个文件没关系,绿色包打一下就行了。大部分用户还是可以接受的
参考技术B 请百度一下这个:ILMerge追问

不借助这个程序,还有其他方法吗?好像e语言可以,vb.net呢?

追答

可以的啊,你先要学会释放资源,然后就是一个普通的文件,然后就是利用反射读取和运行程序集。不过只要用户足够聪明,还不是可以探测到你用了哪些dll啊?

追问

其实我只是觉得~因为本来就是小工具~用了第三方控件所以程序同级下就多了一堆dll,感觉很乱~要是能合并到程序里那就好了

追答

劝你还是别花心思掩饰什么了。用了第三方控件很令人羞耻吗?C:\\Winodws下还不是大堆dll,微软都不怕你看到。。。

本回答被提问者采纳

VB.NET中的常用方法

一、如何使用dll库:

  dll库是动态链接库,一般是别人提供的,用来做二次开发,相当于别人把一些函数包装在dll中,已经生成可以链接文件,你只能调用,但是不能看到方法的实现。所以给你提供dll的人一般也会提供dll的库函数说明,说明中会告诉你里面的函数的返回值,参数等一些东西。

  1、要使用dll库中的方法,首先把dll复制粘贴在你的.net项目中的\bin\Debug路径下面。

  2、在项目中新建一个模块Module,然后在里面声明要用的函数。例如:我新建一个叫API的模块,然后声明函数,具体过程如下:

  

Imports System.Text
Module API

    驱动加载函数
    Public Declare Function RDR_LoadReaderDrivers Lib "rfidlib_reader.dll" (ByVal path As String) As Integer
    Public Declare Function RDR_GetLoadedReaderDriverCount Lib "rfidlib_reader.dll" () As Integer

    设备连接、断开函数
    Public Declare Function RDR_Open Lib "rfidlib_reader.dll" (ByVal connstr As String, ByRef hr As UIntPtr) As Integer
    Public Declare Function RDR_Close Lib "rfidlib_reader.dll" (ByVal hr As UIntPtr) As Integer

    获取错误代码
    Public Declare Function RDR_GetReaderLastReturnError Lib "rfidlib_reader.dll" (ByVal hr As UIntPtr) As Integer

        Public Declare Function RDR_GetTagDataReportCount Lib "rfidlib_reader.dll" (ByVal hr As UIntPtr) As UInt32



    以下是读取读卡器参数的函数
    Public Declare Function RDR_GetReaderInfor Lib "rfidlib_reader.dll" (ByVal hr As UIntPtr, ByVal Type As Byte, ByRef buffer As StringBuilder, ByRef nSize As UInt32) As Integer

    以下是盘卡函数
    Public Declare Function RDR_CreateInvenParamSpecList Lib "rfidlib_reader.dll" () As UIntPtr
    Public Declare Function ISO15693_CreateInvenParam Lib "rfidlib_aip_iso15693.dll" (ByVal hInvenParamSpecList As UIntPtr, ByVal AntennaID As Byte, ByVal en_afi As Byte, ByVal afi As Byte, ByVal slot_type As Byte) As UIntPtr
    Public Declare Function RDR_TagInventory Lib "rfidlib_reader.dll" (ByVal hr As UIntPtr, ByVal AIType As Byte, ByVal AntennaCount As Byte, ByRef AntennaIDs As Byte, ByVal InvenParamSpecList As UIntPtr) As Integer AntennaIDs传入数组的第一个元素地址
    Public Declare Function RDR_GetTagDataReport Lib "rfidlib_reader.dll" (ByVal hr As UIntPtr, ByVal Seekpos As Byte) As UIntPtr
    Public Declare Function ISO15693_ParseTagDataReport Lib "rfidlib_aip_iso15693.dll" (ByVal hTagReport As UIntPtr, ByRef aip_id As UInt32, ByRef tag_id As UInt32, ByRef ant_id As UInt32, ByRef dsfid As Byte, ByRef uid As Byte) As Integer


    以下是销毁盘点参数列表
    Public Declare Function DNODE_Destroy Lib "rfidlib_reader.dll" (ByVal dn As UIntPtr) As Integer

    盘点卡的两个宏定义
    Public Const RFID_SEEK_FIRST = 1
    Public Const RFID_SEEK_NEXT = 2

    连接卡
    Public Declare Function ISO15693_Connect Lib "rfidlib_aip_iso15693.dll" (ByVal hr As UIntPtr, ByVal tagType As UInt32, ByVal address_mode As Byte, ByVal uid() As Byte, ByRef ht As UIntPtr) As Integer

    读卡
    Public Declare Function ISO15693_ReadMultiBlocks Lib "rfidlib_aip_iso15693.dll" (ByVal hr As UIntPtr, ByVal ht As UIntPtr, ByVal readSecSta As Byte, ByVal blkAddr As UInt32, ByVal numOfBlksToRead As UInt32, ByRef numOfBlksRead As UInt32, ByRef bufBlocks As Byte, ByVal nSize As UInt32, ByRef bytesBlkDatRead As UInt32) As Integer

    写卡
    Public Declare Function ISO15693_WriteMultipleBlocks Lib "rfidlib_aip_iso15693.dll" (ByVal hr As UIntPtr, ByVal ht As UIntPtr, ByVal blkAddr As UInt32, ByVal numOfBlks As UInt32, ByVal newBlksData() As Byte, ByVal bytesToWrite As UInt32) As Integer









    Public Declare Function LSG_CmdGetReports Lib "rfidlib_LSGate.dll" (ByVal hr As Long, ByVal Flag As Byte, ByVal recordsToGet As Byte) As Integer
    Public Declare Function LSG_ParseSCEventData Lib "rfidlib_LSGate.dll" (ByVal hr As Long, ByVal slData As String, ByVal nSize As Long, ByRef dir As Byte, ByRef m_time As Byte) As Integer
    Public Declare Function LSG_CmdGetCurrentFlowOfPeople Lib "rfidlib_LSGate.dll" (ByVal hr As Long, ByRef inFlow As Long, ByRef outFlow As Long) As Integer
    Public Declare Function LSG_CmdResetFlowOfPeople Lib "rfidlib_LSGate.dll" (ByVal hr As Long, ByVal mFlg As Byte) As Integer
    Public Declare Function LSG_CmdReverseDirection Lib "rfidlib_LSGate.dll" (ByVal hr As Long) As Integer
    Public Declare Function LSG_CmdGetSystemTime Lib "rfidlib_LSGate.dll" (ByVal hr As Long, ByRef year As Long, ByRef month As Byte, ByRef day As Byte, ByRef hour As Byte, ByRef minute As Byte, ByRef second As Byte) As Integer
    Public Declare Function LSG_CmdSetSystemTime Lib "rfidlib_LSGate.dll" (ByVal hr As Long, ByVal year As Long, ByVal month As Byte, ByVal day As Byte, ByVal hour As Byte, ByVal minute As Byte, ByVal second As Byte) As Integer


    Public Declare Function MultiByteToWideChar Lib "kernel32 " (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpMultiByteStr As Long, ByVal cchMultiByte As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long) As Long
    Public Declare Function WideCharToMultiByte Lib "kernel32 " (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long, ByVal lpMultiByteStr As Long, ByVal cchMultiByte As Long, ByVal lpDefaultChar As Long, ByVal lpUsedDefaultChar As Long) As Long
    Public Const CP_ACP = 0  default to ANSI code page
    Public Const CP_UTF8 = 65001  default to UTF-8 code page

End Module

 

声明完的函数我就可以在项目中调用了,例如:

     ‘设备连接串
        Dim connStr = "RDType=RD201;CommType=COM;COMName=" + CmboxcommCanBeUse.SelectedItem + ";BaudRate=38400;Frame=8E1;BusAddr=255"
        Dim connectOK As Integer = 99
        connectOK = RDR_Open(connStr, hr)

以上代码中的RDR_Open()函数就是在API模块中声明的,函数所在的位置是rfidlib_reader.dll中。

 

二、常用的一些方法:

Now()     获取当前日期时间,

Format() 格式化日期时间函数:

 Format(Now(), "yyyy-MM-dd-hh-mm-ss")

 

DataGridView用法:

GoodDataGridView.Rows.Add()为添加一行

GoodDataGridView.Rows.RemoveAt(1) 为删除第一行

GoodDataGridView(0, 0).Value = "序号" 为给某列某行的单元格设置值。其中(0,0)中前面的数字代表第几列,后面的数字代表第几行。
     GoodDataGridView.Rows.Add()
        GoodDataGridView(0, 0).Value = "序号"
        GoodDataGridView(1, 0).Value = "商品编码"
        GoodDataGridView(2, 0).Value = "商品名称"
        GoodDataGridView(3, 0).Value = "商品价格"

 

定义数组并初始化:

      定义一组商品的属性的二进制编码,用来保存当前连接的标签的内容
        Dim goodsNumb() As Byte = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
        Dim goodsName() As Byte = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
        Dim goodsPric() As Byte = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

 

 UTF8 编码与解码:

Imports System.Text

Module UTF8

    UTF8编码函数
    Public Function StringToUTF8Bytes(ByVal strData As String) As Byte()

        Dim bytes() As Byte
        bytes = Encoding.UTF8.GetBytes(strData)
        Return bytes

    End Function

    UTF8解码函数
    Public Function UTF8BytesToString(ByVal strData() As Byte) As String

        Dim retstring As String
        retstring = Encoding.UTF8.GetString(strData)
        Return retstring

    End Function

End Module

 

以上是关于vb.net把dll放到程序的Resources资源里面,能直接调用Resources里面的dll吗?的主要内容,如果未能解决你的问题,请参考以下文章

vb.net引用Dll的问题

VB .NET 制作的DLL无法被 .NET 程序引用

VB.NET中的常用方法

VB.net编写的dll,供vb6调用时dll中的函数不可见?

从“My.resources”VB.net 复制文件的进度条

vb.net如何调用dll(动态链接库)