Solved

For Ark!

Posted on 2002-04-13
10
341 Views
Last Modified: 2008-03-03
more background: I am trying to make a web component that will take a specified image from the web and convert it to RTFText.

How I did this is use your coe below to get the image and then populate a picturebox --> then copy that into the RTF box and finally, display the RTFText to browser (the goal of this app) [actually because my asp code does all the rest of the work)

Anyway, In your URL_To_Picture function (below), it works excellent when VB is open, but when I create the ActiveX .dll it get the following message:



HTTP 500.100 - Internal Server Error - ASP error
Internet Information Services
...
Error Type:
URLImage2RTF (0x800A0035)
File not found: 'C:\WINNT\TEMP\dummy'
/8/usage.asp, line 26


any ideas?  again -- it works fine if I run the code with VB open.


-----------------------------------------------------
ORIGINAL QUESTION
-----------------------------------------------------
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=visualbasic&qid=20287834
-----------------------------------------------------

Does any one know how to populate a picture from a url?

picture1.picture = loadpicture("<filename>")

doesnt work with url?
Thanks
-----------------------------------------------------

Accepted Answer
From: Ark Date: 04/12/2002 11:02PM PST
Text Below
Question History
Accepted Answer
From: Ark  Date: 04/12/2002 11:02PM PST  
-----------------------------------------------------
Hi

Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nSize As Long, ByVal
lpBuffer As String) As Long
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As
Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long)
As Long

Public Sub URL_To_Picture(ByVal sURL As String, pb As PictureBox)
 Dim sTemp As String, sHTML As String
 sTemp = GetTempDir
 If Right(sTemp,1) <> "\" Then sTemp = sTemp & "\"
 sTemp = sTemp & "dummy"
 If Dir$(sTemp) <> "" Then Kill sTemp
 Save_File_URL sTemp, sURL
 pb.Picture = LoadPicture(sTemp)
 Kill sTemp
End Sub

Private Function Save_File_URL(ByVal sFileName As String, ByVal sURL As String) As Long
  Call URLDownloadToFile(0&, sURL, sFileName, 0, 0)
End Function

Private Function GetTempDir() As String
 Dim tmp As String
 tmp = Space$(256)
 Call GetTempPath(Len(tmp), tmp)
 GetTempDir = TrimNull(tmp)
End Function

Private Function TrimNull(item As String)
 Dim pos As Integer
 pos = InStr(item, Chr$(0))
 If pos Then
    TrimNull = Left$(item, pos - 1)
 Else
    TrimNull = item
 End If
End Function
0
Comment
Question by:ryderjam
  • 5
  • 5
10 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 6939547
w/o knowing exactly how you have implemented the dll in your ASP page, my guess is that the client is trying to access an image on your server which you have already deleted (the last line in the function "kills" the file)
0
 

Author Comment

by:ryderjam
ID: 6940374
AzraSound!

i tried the kill -- is it possible to maybe store it to clipboard instead of a temp file ... do you know how to do that?
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6940529
i'm sure you could store it in the clipboard, but how you will point to that in your asp page so that the client can download it, i dont know...unless, of course, you stream the image to the client (which means you could, then, technically, delete the temp file once you are done with it).

streaming would only work, i think, if the image was the only thing being sent to the client.  to be sure that was your problem, did you just remove the Kill statement and see if it worked?
0
 

Author Comment

by:ryderjam
ID: 6940584
yeah I tried removing the kill statements.  But that didnt quite do it.  

Not sure what to do now.
0
 

Author Comment

by:ryderjam
ID: 6940677
again BTW it works perfect when I have visual basic open as oposed to actually producing the .dll. --which is why I am suspicious :)
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 28

Expert Comment

by:AzraSound
ID: 6940895
can you post your asp code and how you call the dll and display the picture?
0
 

Author Comment

by:ryderjam
ID: 6941001
Sure!
=======
VB CODE
=======
Option Explicit
Public ASPsc As ScriptingContext
Private Application As Object
Private Request As Object
Private Session As Object
Private Response As Object
Private Server As Object

Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nSize As Long, ByVal lpBuffer As String) As Long
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Private mvarPictureURL As Variant
Private mvarPictureFile As Variant
Private mvarTempDir As Variant
Private mvarSaveFileName As Variant
Private mvarShowRTFText As Boolean
Public Property Let PictureURL(ByVal vData As Variant)
    mvarPictureURL = vData
End Property
Public Property Get PictureURL() As Variant
    PictureURL = mvarPictureURL
End Property
Public Property Let PictureFile(ByVal vData As Variant)
    mvarPictureFile = vData
End Property
Public Property Get PictureFile() As Variant
    PictureFile = mvarPictureFile
End Property
Public Property Let TempDir(ByVal vData As Variant)
    mvarTempDir = vData
End Property
Public Property Get TempDir() As Variant
    TempDir = mvarTempDir
End Property
Public Property Let SaveFileName(ByVal vData As Variant)
    mvarSaveFileName = vData
End Property
Public Property Get SaveFileName() As Variant
    SaveFileName = mvarSaveFileName
End Property
Public Property Let ShowRTFText(ByVal vData As Boolean)
    mvarShowRTFText = vData
End Property
Public Property Get ShowRTFText() As Boolean
    ShowRTFText = mvarShowRTFText
End Property
Public Sub OnStartPage(ASPScriptingContext As ScriptingContext)
Set ASPsc = ASPScriptingContext
End Sub
Private Function Save_File_URL(ByVal sFileName As String, ByVal sURL As String) As Long
  Call URLDownloadToFile(0&, sURL, sFileName, 0, 0)
End Function
Private Function GetTempDir() As String
 Dim tmp As String
 tmp = Space$(256)
 Call GetTempPath(Len(tmp), tmp)
 GetTempDir = TrimNull(tmp)
End Function
Private Function TrimNull(item As String)
 Dim pos As Integer
 pos = InStr(item, Chr$(0))
 If pos Then
    TrimNull = Left$(item, pos - 1)
 Else
    TrimNull = item
 End If
End Function
Public Sub MakeRTF()
Set Application = ASPsc.Application

Set Request = ASPsc.Request
Set Session = ASPsc.Session
Set Response = ASPsc.Response
Set Server = ASPsc.Server
 
If Len(mvarPictureFile) > 0 Then
   Form1.Picture1.Picture = LoadPicture(mvarPictureFile)
Else
   Dim sTemp As String, sHTML As String, sURL As String
   sURL = mvarPictureURL

   If Len(mvarTempDir) > 0 Then
      sTemp = mvarTempDir
   Else
      sTemp = GetTempDir
   End If

   If Right(sTemp, 1) <> "\" Then sTemp = sTemp & "\"
   sTemp = sTemp & "_tmp"
   'If Dir$(sTemp) <> "" Then Kill sTemp
   Save_File_URL sTemp, sURL
   Form1.Picture1.Picture = LoadPicture(sTemp)
   'Kill sTemp
End If
Form1.InsertPictureInRichTextBox Form1.RichTextBox1, Form1.Picture1.Picture

If Len(mvarSaveFileName) > 0 Then
   Form1.RichTextBox1.SaveFile mvarSaveFileName
End If
If mvarShowRTFText = True Then
   Response.Write (Form1.RichTextBox1.TextRTF)
End If

Form1.Picture1.Picture = Nothing
Form1.RichTextBox1.Text = ""
Form1.RichTextBox1.TextRTF = ""

End Sub

========
ASP CODE
========
<%
'-----------------------------------------------------------------------------------------------------'
                                                     '
' Usage:                                                                                              '
'  1) Select a picture to load, either from a file or a URL (Inherits IE internet settings (ie. proxy)'                                  '
'                                                                                                     '
'     ** If you select PictureFile, then PictureURL will have no effect.                              '
'                                                                                                     '
'  2) Optional. Specify a temp directory. **Default is WINNT/TEMP - You must have write permissions)  '
'               Has no effect if PictureFile option is used **                                        '
'                                                                                                     '
'  3) Optional. SaveFileName - if you want to produce a file as well, specify dir & location          '
'                                                                                                     '
'  4) Optional. ShowRTFText - If you want to display the actual rtf text to your browser set to true  '
'                                                                                                     '
'  5) MakeRTF                                                                                         '
'-----------------------------------------------------------------------------------------------------'

set RTF = Server.CreateObject("URLImage2RTF.Convert")
'RTF.PictureFile = "d:\inetpub\wwwroot\4\101206.jpg"  ' Optional. Load from a file  (PictureURL will have no effect)
RTF.PictureURL = "some.jpg"  ' Optional. Picture to load from URL
RTF.TempDir = "" ' Optional. If blank, uses computers temp directory specified in windows
RTF.SaveFileName = "C:\xxy.rtf" ' Optional. Use this to save you RTF picture to a file
RTF.ShowRTFText = True ' Optional. Use this to display the rtf text of your image
RTF.MakeRTF  'Required!
set obj = nothing 'Required!
%>
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6942293
I dont even see where the error may be occurring (you dont use that URL_To_Picture function in your DLL).  So where exactly is the error occurring?  Have you tried debugging your component and stepping through the code to see, exactly, what is going on?
0
 

Author Comment

by:ryderjam
ID: 6942373
exactly.. the code runs fine when VB is running it.  nothing to debug -- because it does what its expected to.  

See, The URL_To_Picture function is in the code (or most of it) -- the only difference is that I call it directory with out being in a function. Anyway, like I say it seems to work great while visual basic has it in run mode. But when I compile the .dll and deploy it over IIS server, I get those errors, I thought it might be permissions, so I set the dir to everyone and full control.  So thats not it.

still trying
Jim
0
 
LVL 28

Accepted Solution

by:
AzraSound earned 300 total points
ID: 6942496
I was suggesting to debug the dll as a dll while running it in your ASP page (perhaps we arent on the same page here regarding how to debug).

Can we take a look at the form's InsertPictureInRichTextBox method?

BTW, how does the URL work if all you pass to the component parameter is "some.jpg"?  I imagine it needs a fully qualified URL to work (i.e., http://somesite.com/some.jpg")
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now