468,505 Members | 1,801 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,505 developers. It's quick & easy.

Calling DLL Function inside Classic ASP

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

1 3322
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.

Similar topics

1 post views Thread by Bryan Parkoff | last post: by
6 posts views Thread by jchao123 | last post: by
16 posts views Thread by Saroj | last post: by
2 posts views Thread by Syl | last post: by
15 posts views Thread by dspfun | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.