Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Error 12005 Trying to Call WINHTTPCONNECT Function in WINHTTP DLL from VB

Posted on 2008-06-25
10
1,931 Views
Last Modified: 2013-12-20
I am trying to call Winhttp.dll from a VB app. I specifically need to carry out this process using windows native DLL's, not COM objects.
When I run the attached code, I get the error 12005, could someone explain why, and offer a solution.
Please note my final solution will be adapted to run in an uncommon language (Omnis 7), so please keep this in mind for your replies.
Public Declare Function WinHttpOpen Lib "WinHttp.dll" (ByVal pwszUserAgent As String, ByVal dwAccessType As Int32, ByVal pwszProxyName As String, ByVal pwszProxyBypass As String, ByVal dwFlags As Int32) As Int32
    Public Declare Function WinHttpConnect Lib "WinHttp.dll" (ByVal Hsession As Int32, ByVal SiteAddress As String, ByVal Port_Number As Int32, ByVal dwvalue As Int32) As Int32
 
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim hsession As Int32
        Dim hconnect As Int32
        Dim Herror As Int32
        'Dim Exception As String
        Dim URL As String
 
        URL = "www.google.co.uk"
 
 
        hsession = WinHttpOpen("Visual Basic", 0, "", "", 0)
        hconnect = WinHttpConnect(hsession, URL, 80, 0)
 
        Herror = Err.LastDllError
        If Herror = 12005 Then
            MsgBox("Bad Url")
        End If
 
    End Sub

Open in new window

0
Comment
Question by:lonefox_illuminus
  • 5
  • 4
10 Comments
 

Author Comment

by:lonefox_illuminus
ID: 21866513
points changed
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 21978407
Try using

URL = "http://www.google.co.uk"

Some of the low level APIs can be picky about the URL format.  Google doesn't like being screen scraped either, so you might change to a different site for testing.
0
 

Accepted Solution

by:
lonefox_illuminus earned 0 total points
ID: 21980735
I managed to acheive what I was looking for by using Wininet.dll instead, never had any success with winhttp.dll in the end, despite asking on numerous boards, and scouring the web for answers.
MSDN is quite clear in it's definition for the URL to be in the format of my original question, and having tried all combinations including with and without protocol prefix, suffixing / characters etc, all with no success, the most likely reason I can deduce is something to do with the string handling between VB and C++.
This question is closed, my suggestion for anyone else with the same problem.
Use Wininet.dll instead.
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 38

Expert Comment

by:PaulHews
ID: 21982179
Suggest that since there is no solution to the OP problem that the question be deleted instead.
0
 

Author Comment

by:lonefox_illuminus
ID: 21983171
Solution is to not use winhttp.dll when calling from VB, and to use wininet.dll instead. IMO this is worthy information that might have saved me weeks of head scratching, had I found a reference to it online.
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 21983194
As this is VB.NET I'm unclear why you would not want to use the .NET framework tools (not COM objects) instead of an API.
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 21983197
(Note that I only just realized that the question targetted .NET framework...)
0
 

Author Comment

by:lonefox_illuminus
ID: 21983296
As per my question,

"I specifically need to carry out this process using windows native DLL's, not COM objects."

"Please note my final solution will be adapted to run in an uncommon language (Omnis 7),"

I think u realised that now though.

Omnis 7 doesn't support COM objects, after testing in VB to conclude the same error occured, I opted to ask my question targetting VB to increase the likelyhood of a response. There's only a handful of us out here coding in Omnis.
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 21983316
Anyway, no objection to PAQ... I'll get a moderator to close the question with your solution.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MS Date Picker 64 bit 32 bit issue 12 60
Problem to start Neon 20 120
VBA - If Bookmark = "XXBOOKMARKXX" then 15 40
Collapse and expand table in Word 2010 2 31
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

839 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