开发者

Inconsistent Behavior From Declared DLL Function

Why might my GetRawData declared function return a correct value when called from my VB.NET application, but return zero when called from my ASP.NET page?

The code is exactly the same except for class type difference (Form / Page) and calling event handler (Form1_Load, Page_Load).

Note: In the actual code, #DLL# and #RAWDATAFILE# are both absolute filenames to my DLL and raw data file respectively.

Note: The DLL file was not created by Visual Studio.

Form1.vb

Public Class Form1

    Declare Auto Function GetRawData Lib "#DLL#" (ByVal filename() As Byte, _
                                                  ByVal byteArray() As Byte, _
                                                  ByVal length As Int32) As Int32


    Private Sub Form1_Load(ByVal sender As System.Object, _
                           ByVal e As System.EventArgs) Handles MyBase.Load

        Dim buffer(10485760) As Byte
        Dim msg As String, length As Integer = 10485760
        Dim filename As String = "#RAWDATAFILE#"
        length = GetRawData(Encoding.Default.GetBytes(filename), buffer, length)

Default.aspx.vb

Partial Public Class _Default
    Inherits System.Web.UI.Page

    Declare Auto Function GetRawData Lib "#DLL#" (ByVal filename() As Byte, _
                                                  ByVal byteArray() As Byte, _
                                                  ByVal length As Int32) As Int32


    Protected Sub Page_Load(ByVal sender As Object, _
                            ByVal e As System.EventArgs) Handles Me.Load

        Dim buffer(10485760) As Byte
        Dim msg As String, length As Integer = 10485760
        Dim filename As String = "#RAWDATAFILE#"
        length开发者_运维技巧 = GetRawData(Encoding.Default.GetBytes(filename), buffer, length)


Try putting your dll and file in your ASP.Net bin directory and referencing it from there. The DLL may be silently failing because of security issues.


A slightly less then random guess: the ASP.NET process doesn't have permission to open the the file specified by "#RAWDATAFILE#"


This DLL function appears to take a file name and return some data from the file into a buffer. You don't specify the full path to the file, "#rawdatafile#" would be a relative path. The odds that this works in an asp.net page are very small. Specify a full path instead (like "c:\blah\something.txt" instead of "something.txt").

Lots of other possible failure modes. Like the DLL path and whether the asp.net account has the necessary rights to access these files.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜