1

我試圖在LightSwitch應用程序使用下面的代碼來打印條形碼如何訪問本地的dll在LightSwitch應用程序

 
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 

我得到這個錯誤:

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

我明白這一點是因爲.net framework v4內置的安全性,我也嘗試添加securitySafeCritical Attribute,但它似乎完全被忽略。

我在做什麼錯了?我是Silverlight和LightSwitch的絕對新手。此應用程序應該用完瀏覽器。

回答

0

我假設你正在嘗試從客戶端應用程序執行此操作。如果是這種情況,那麼這是不可能的。 LightSwitch基於Silverlight 4,不支持調用本機代碼。它只支持通過COM自動化調用本機代碼,使用通過AutomationFactory類。請參閱

相關問題