By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,162 Members | 1,061 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,162 IT Pros & Developers. It's quick & easy.

Calling DLL Function inside Classic ASP

P: 3
Hello,
I need to call .net dll function inside of classic asp.
So i regsitered dll and tlb file with regasm.exe (and /codebase parameter). there is no problem.
There is a sql databse and some table have image type data (inside has picture data). I want to send image data to dll function like a image or byte() type.

my asp code part:
================================================== =======
Expand|Select|Wrap|Line Numbers
  1. Set jpg = Server.CreateObject("ad_jpeg.Jpeg")
  2. jpg.openBinary(rs("prev"))      'prev is sql 2008 image type
  3.  
  4. my .net dll function
  5. =========================================================
  6.     Public Function openBinary(ByVal gln As Object) As Boolean
  7.         If gln Is Nothing Then
  8.             lastError = "No binary data"
  9.             Return False
  10.         Else
  11.             Try
  12.                 Dim img As Image
  13.                 Dim ms = New MemoryStream(CType(gln, Byte()))
  14.                 img = Image.FromStream(ms)
  15.                 If img IsNot Nothing Then
  16.                     jpeg = img
  17.                     Return True
  18.                 Else
  19.                     lastError = "Incoming data error"
  20.                     Return False
  21.                 End If
  22.             Catch ex As Exception
  23.                 lastError = "Incoming type of data : " & gln.GetType().ToString & vbCrLf & ex.ToString
  24.                 Return False
  25.             End Try
  26.         End If
  27.     End Function

asp browse this error:
Incoming type of data : System.__ComObject
System.InvalidCastException: 'System.__ComObject' cannot assing byte type etc....
Dec 25 '14 #1

✓ answered by adincergok

I've solved myself successfully (I've try all data types)...

My code here:
=====================================
Expand|Select|Wrap|Line Numbers
  1.     Public Function openBinary(ByVal gln As String) As Boolean
  2.         If String.IsNullOrEmpty(gln) Then
  3.             lastError = "No binary data"
  4.             Return False
  5.         Else
  6.             Try
  7.                 Dim array() As Byte = System.Text.Encoding.Unicode.GetBytes(gln)
  8.                 Dim img As Image
  9.                 Dim ms = New MemoryStream(array)
  10.                 img = Image.FromStream(ms)
  11.                 If img IsNot Nothing Then
  12.                     jpeg = img
  13.                     Return True
  14.                 Else
  15.                     lastError = "Incoming data error"
  16.                     Return False
  17.                 End If
  18.             Catch ex As Exception
  19.                 lastError = "Incoming type of data : " & gln.GetType().ToString & vbCrLf & ex.ToString
  20.                 Return False
  21.             End Try
  22.         End If
  23.     End Function

Share this Question
Share on Google+
1 Reply


P: 3
I've solved myself successfully (I've try all data types)...

My code here:
=====================================
Expand|Select|Wrap|Line Numbers
  1.     Public Function openBinary(ByVal gln As String) As Boolean
  2.         If String.IsNullOrEmpty(gln) Then
  3.             lastError = "No binary data"
  4.             Return False
  5.         Else
  6.             Try
  7.                 Dim array() As Byte = System.Text.Encoding.Unicode.GetBytes(gln)
  8.                 Dim img As Image
  9.                 Dim ms = New MemoryStream(array)
  10.                 img = Image.FromStream(ms)
  11.                 If img IsNot Nothing Then
  12.                     jpeg = img
  13.                     Return True
  14.                 Else
  15.                     lastError = "Incoming data error"
  16.                     Return False
  17.                 End If
  18.             Catch ex As Exception
  19.                 lastError = "Incoming type of data : " & gln.GetType().ToString & vbCrLf & ex.ToString
  20.                 Return False
  21.             End Try
  22.         End If
  23.     End Function
Dec 25 '14 #2

Post your reply

Sign in to post your reply or Sign up for a free account.