Inconsistent Behavior From Declared DLL Function
Posted
by Steven
on Stack Overflow
See other posts from Stack Overflow
or by Steven
Published on 2010-05-21T17:11:21Z
Indexed on
2010/05/21
17:20 UTC
Read the original article
Hit count: 212
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)
© Stack Overflow or respective owner