Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTTPS in a DLL

Status
Not open for further replies.

Griffyn

Programmer
Jul 11, 2002
1,077
AU
Hi all,

I can get HTTPS working using TidHTTP and the SSL DLLs no problem. I'm working on a project that needs to do a HTTP.Post using SSL from within a DLL. I'm not that experienced using DLLs - I've got it loaded ok, and can call the DLL procedure, but it seems that the line in the DLL that does the HTTP.Post causes an Access Violation (handling exceptions within the DLL was a learning experience too). And yes, I've created the HTTP object :)

From what I've read, "some 3rd party components can cause AVs when used within a DLL" - which I'm presuming is the case with TidHTTP. Can anyone give me a hand in getting this to work, or a workaround?

Many thanks!
 
It's been a while, but I had problems getting Indy components to work from anywhere but the procedure that instantiated them. These weren't particularly well-written, and many of the methods were just stubs--unimplemented.

IOW, I'd start now by assuming that I have to debug TidHTTP.
 
I have used many of the Indy 10 components in lots of small and larger projects, and have had no issues with them before. Because it's in a DLL, I can't begin to debug TidHTTP to see at exactly what point the AV is occuring.
 
Sorry, I omitted the word "internet." It should have read, "...I had problems getting Indy internet components to work..." (Namely, I found the ftp and http components flaky as well as unfinished.)

And I can see that this is no help if you're determined to use the Indy components. (I solved my problems by going to TurboPower, which has since deteriorated in PD.)
 
I'm not determined to use anything - just need HTTPS in a DLL, that's all. I've been presuming that the majority of HTTP components out there don't support HTTPS, which was why I've been trying to use TidHTTP.
 
Griffyn, did you create the IdHttp object on the fly or are you using a datamodule?

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
on the fly. from the DLL code
Code:
[b]function[/b] CommsTest: Boolean;
[b]var[/b]
  ss : TStringList;
[b]begin[/b]
  [b]try[/b]
    ss := TStringList.Create;
    [b]try[/b]
      ss.Add([teal]'test=blah'[/teal]);
      Result := SameText(HTTP.Post(url + [teal]'test.asp'[/teal], ss), [teal]'OK'[/teal]);
    [b]finally[/b]
      ss.Free;
    [b]end[/b];
  [b]except[/b]
    [b]on[/b] E: Exception [b]do[/b]
    [b]begin[/b]
      LastErrorMessage := E.Message;
      Result := False;
    [b]end[/b];
  [b]end[/b];
[b]end[/b];

[b]procedure[/b] Uninitialize;
[b]begin[/b]
  [b]try[/b]
    HTTP.Free;
  [b]finally[/b]
    ExitProc := SaveExit;
  [b]end[/b];
[b]end[/b];

[b]exports[/b]
  CommsIssuePoints,
  CommsTest,
  CommsLastError;

[b]begin[/b]
  SaveExit := ExitProc;
  ExitProc := @Uninitialize;
  HTTP := TidHTTP.Create;
[b]end[/b].

In my calling program, LastErrorMessage (returned via the CommsLastError function) contains the AV exception message) - I can't tell exactly which line in CommsTest is causing the exception - I'm presuming it's the HTTP.Post line.
 
You know what? I'm stupid.

To use SSL I need to add a SSL IOHandler. Something possessed me to think TidHTTP would take care of this.

Code:
[b]procedure[/b] Uninitialize;
[b]begin[/b]
  [b]try[/b]
    HTTP.IOHandler.Free;
    HTTP.Free;
  [b]finally[/b]
    ExitProc := SaveExit;
  [b]end[/b];
[b]end[/b];

[b]exports[/b]
  CommsIssuePoints,
  CommsTest,
  CommsLastError;

[b]begin[/b]
  SaveExit := ExitProc;
  ExitProc := @Uninitialize;
  HTTP := TidHTTP.Create;
  HTTP.IOHandler := TIdSSLIOHandlerSocketOpenSSL.Create;
  LastErrorMessage := [teal]''[/teal];
[b]end[/b].

Works now. Thanks for trying harebrain and whorsdaddy.
 
what can i say?
[thumbsup]

Cheers,
Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Not stupid; just needed some distraction for it to percolate to the other side of your brain. (That's MY story, and I stick to it!) :)
 
While I got it working, I've realised through more playing that the lack of the SSL IOHandler wasn't the primary issue. The CommsLastError function I have which simply returns the LastErrorMessage string was of type String and not ShortString. Because I wasn't using a replacement memory manager, it was this line that was causing the AV I'm pretty sure. The initial exception was being caused by the lack of the SSL IOHandler, but it wasn't an AV and was more specific.
 
yep, use FastMM4 to solve your problem :)

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top