How to access native dll in lightswitch application

I'm trying to print a barcode using the following code in Lightswitch Application

Imports System.Security

Namespace LightSwitchApplication


    Public Class EditableAS_TempStickersGrid

        'Declaration of Private Subroutine
        Private Declare Sub openport Lib "tsclib.dll" (ByVal PrinterName As String)
        Private Declare Sub closeport Lib "tsclib.dll" ()
        Private Declare Sub sendcommand Lib "tsclib.dll" (ByVal command_Renamed As String)
        Private Declare Sub setup Lib "tsclib.dll" (ByVal LabelWidth As String, ByVal LabelHeight As String, ByVal Speed As String, ByVal Density As String, ByVal Sensor As String, ByVal Vertical As String, ByVal Offset As String)
        Private Declare Sub downloadpcx Lib "tsclib.dll" (ByVal Filename As String, ByVal ImageName As String)
        Private Declare Sub barcode Lib "tsclib.dll" (ByVal X As String, ByVal Y As String, ByVal CodeType As String, ByVal Height_Renamed As String, ByVal Readable As String, ByVal rotation As String, ByVal Narrow As String, ByVal Wide As String, ByVal Code As String)
        Private Declare Sub printerfont Lib "tsclib.dll" (ByVal X As String, ByVal Y As String, ByVal FontName As String, ByVal rotation As String, ByVal Xmul As String, ByVal Ymul As String, ByVal Content As String)
        Private Declare Sub clearbuffer Lib "tsclib.dll" ()
        Private Declare Sub printlabel Lib "tsclib.dll" (ByVal NumberOfSet As String, ByVal NumberOfCopy As String)
        Private Declare Sub formfeed Lib "tsclib.dll" ()
        Private Declare Sub nobackfeed Lib "tsclib.dll" ()
        Private Declare Sub windowsfont Lib "tsclib.dll" (ByVal X As Short, ByVal Y As Short, ByVal fontheight_Renamed As Short, ByVal rotation As Short, ByVal fontstyle As Short, ByVal fontunderline As Short, ByVal FaceName As String, ByVal TextContent As String)


        Private Sub Print_Stickers_Execute()
            ' Write your code here.

            printSticker("244001", "", "test code", "")
            For Each sticker In AS_TempStickers

                'code to print barcode

                Dim p As AS_ProductDetail = New AS_ProductDetail
                p.SerialNo = sticker.SerialNo
                p.dashCommerce_Store_Sku = sticker.dashCommerce_Store_Sku
                p.CurrentLocation = "STICKER"

                sticker.Delete()
                Me.Save()

            Next

        End Sub
        
        Private Sub printSticker(code1 As String, code2 As String, str1 As String, str2 As String)



            Dim B1 As String = code1
            Dim WT1 As String = str1

            'Connect to a printer and set up the parameters'
            Call openport("TSC TTP-244 Plus")
            Call setup("102", "64", "4.0", "7", "0", "2", "0")
            Call clearbuffer()
            Call sendcommand("DIRECTION 1")
            Call sendcommand("SET CUTTER OFF") ' Or the number of printout per cut'



            Call barcode("40", "300", "128", "80", "1", "0", "2", "2", B1)

            'Print a text with Windows Arial font'

            Call windowsfont(120, 440, 40, 0, 0, 0, "ARIAL", WT1)

            'The number of printout sets&copies'

            Call printlabel("1", "1")

            'Disconnect with the printer'

            Call closeport()


        End Sub
    End Class

End Namespace

I'm getting this error :

Methods must be security critical or security safe-critical to call native code.

I understand this is because of the security inbuilt in .net framework v4, I've also tried adding the securitySafeCritical Attribute but it seems its being totally ignored.

What am i doing wrong?. I'm and absolute newbie to Silverlight and LightSwitch. This application is supposed to run out of the browser.


I'm assuming that you are trying to do this from a client application. If this is the case then it's not possible. LightSwitch is based on Silverlight 4, which does not support calling native code. It only supports calling native code via COM Automation, using the through the AutomationFactory class. See the

链接地址: http://www.djcxy.com/p/73424.html

上一篇: 当十进制值为.00时,如何在文字中显示零分

下一篇: 如何在lightswitch应用程序中访问本地dll