Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: URL_COMPONENTS, TUrlComponents and InternetCrackUrl() in C++ Builder 10.1


This question is answered.


Permlink Replies: 9 - Last Post: May 21, 2016 8:13 AM Last Post By: Romeo LeGagahne
Romeo LeGagahne

Posts: 7
Registered: 1/22/16
URL_COMPONENTS, TUrlComponents and InternetCrackUrl() in C++ Builder 10.1  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 17, 2016 4:48 PM
In The Name of The Only One GOD, THE ALL-MIGHTY.

My C++ Builder 10.1 Berlin's _TCHAR is mapped to wchar_t and the clang is enabled.

I am using the InternetCrackUrl() or InternetCrackUrlW() API function with URL_COMPONENTS structure in my codes.

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  pURL = Edit1->Text;
  BOOL iCrack = FALSE;
  wchar_t extra[1024] = {0};
  wchar_t path[INTERNET_MAX_PATH_LENGTH] = {0};
 
  URL_COMPONENTS compon;
  memset(&compon, 0, sizeof(compon));
  compon.dwStructSize = sizeof(compon);
  compon.lpszUrlPath = path;
  compon.dwUrlPathLength = INTERNET_MAX_PATH_LENGTH;
  compon.lpszExtraInfo = extra;
  compon.dwExtraInfoLength = 1024;
 
  iCrack = InternetCrackUrlW(pURL.c_str(), pURL.Length(), 0, compon);
  if (iCrack != NULL)
  {
    wsprintf(Msg, L"UrlPath : %s", compon->lpszUrlPath);
    ShowMessage(Msg);
 
    wsprintf(Msg, L"ExtraInfo : %s", compon->lpszExtraInfo);
    ShowMessage(Msg);
  }
}


But whenever I i try to build the code, it always returns some error messages. These errors occur w/o the & notion in 4th argument of InternetCrackUrlW().

[bcc32c Error] Unit1.cpp(30): reference to 'URL_COMPONENTS' is ambiguous
   WinInet.h(578): candidate found by name lookup is 'URL_COMPONENTS'
  Winapi.WinInet.hpp(152): candidate found by name lookup is 'Winapi::Wininet::URL_COMPONENTS'
[bcc32c Error] Unit1.cpp(31): use of undeclared identifier 'compon'
[bcc32c Error] Unit1.cpp(32): use of undeclared identifier 'compon'
[bcc32c Error] Unit1.cpp(32): use of undeclared identifier 'compon'
[bcc32c Error] Unit1.cpp(33): use of undeclared identifier 'compon'
[bcc32c Error] Unit1.cpp(34): use of undeclared identifier 'compon'
[bcc32c Error] Unit1.cpp(35): use of undeclared identifier 'compon'
[bcc32c Error] Unit1.cpp(36): use of undeclared identifier 'compon'
[bcc32c Error] Unit1.cpp(38): use of undeclared identifier 'compon'
[bcc32c Error] Unit1.cpp(41): use of undeclared identifier 'compon'
[bcc32c Error] Unit1.cpp(44): use of undeclared identifier 'compon'


So, i tried using the scope resolution operator: Wininet::URL_COMPONENTS compon; but other errors are take place. - still w/o the & notion in 4th argument of InternetCrackUrlW().

bcc32c Error] Unit1.cpp(38): no matching function for call to 'InternetCrackUrlW'
  WinInet.h(767): candidate function not viable: no known conversion from 'Wininet::URL_COMPONENTS *' (aka 'Winapi::Wininet::URL_COMPONENTSW *') to 'LPURL_COMPONENTSW' (aka 'URL_COMPONENTSW *') for 4th argument
[bcc32c Error] Unit1.cpp(41): member reference type 'Wininet::URL_COMPONENTS' (aka 'Winapi::Wininet::URL_COMPONENTSW') is not a pointer
[bcc32c Error] Unit1.cpp(44): member reference type 'Wininet::URL_COMPONENTS' (aka 'Winapi::Wininet::URL_COMPONENTSW') is not a pointer


I tried another way to use TURLComponents record (TURLComponents compon;), unfortunately it does not works and got the following errors - still w/o the & notion in 4th argument of InternetCrackUrlW().

[bcc32c Error] Unit1.cpp(38): no matching function for call to 'InternetCrackUrlW'
  WinInet.h(767): candidate function not viable: no known conversion from 'TURLComponents' (aka 'Winapi::Wininet::URL_COMPONENTSW') to 'LPURL_COMPONENTSW' (aka 'URL_COMPONENTSW *') for 4th argument
[bcc32c Error] Unit1.cpp(41): member reference type 'TURLComponents' (aka 'Winapi::Wininet::URL_COMPONENTSW') is not a pointer
[bcc32c Error] Unit1.cpp(44): member reference type 'TURLComponents' (aka 'Winapi::Wininet::URL_COMPONENTSW') is not a pointer


Finally i've successfully compiled the code after I changed the API structure to (LPURL_COMPONENTSW compon;).

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  pURL = Edit1->Text;
  BOOL iCrack = FALSE;
  wchar_t extra[1024] = {0};
  wchar_t path[INTERNET_MAX_PATH_LENGTH] = {0};
 
  LPURL_COMPONENTSW compon;
  memset(&compon, 0, sizeof(compon));
  compon->dwStructSize = sizeof(compon);
  compon->lpszUrlPath = path;
  compon->dwUrlPathLength = INTERNET_MAX_PATH_LENGTH;
  compon->lpszExtraInfo = extra;
  compon->dwExtraInfoLength = 1024;
 
  iCrack = InternetCrackUrlW(pURL.c_str(), pURL.Length(), 0, compon);
  if (iCrack != NULL)
  {
    wsprintf(Msg, L"UrlPath : %s", compon->lpszUrlPath);
    ShowMessage(Msg);
 
    wsprintf(Msg, L"ExtraInfo : %s", compon->lpszExtraInfo);
    ShowMessage(Msg);
  }
}


...but when the buton is pressed an error occurs as show in this pic.

http://postimg.org/image/6qfmviv2p/

Perhaps there are some non-standard things I am doing. Kindly help me where I am doing wrong. Thank you.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: URL_COMPONENTS, TUrlComponents and InternetCrackUrl() in C++ Builder10.1
Correct
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 17, 2016 5:33 PM   in response to: Romeo LeGagahne in response to: Romeo LeGagahne
Romeo wrote:

I am using the InternetCrackUrl() or InternetCrackUrlW() API function

They are the same function, since InternetCrackUrl() maps to InternetCrackUrlW()
when "TCHAR maps to" is set to "wchar_t".

with URL_COMPONENTS structure in my codes.

Since you are calling InternetCrackUrlW() directly, you should use URL_COMPONENTSW
directly to match.

[bcc32c Error] Unit1.cpp(30): reference to 'URL_COMPONENTS' is ambiguous
WinInet.h(578): candidate found by name lookup is 'URL_COMPONENTS'
Winapi.WinInet.hpp(152): candidate found by name lookup is
'Winapi::Wininet::URL_COMPONENTS'

This means you have two different namespaces that are both defining the URL_COMPONENTS
symbol, and both namespaces are in scope in your code. Which is true - Wininet.h
defines the Win32 API URL_COMPONENTS structure in the global namespace, and
then Winapi.WinInet.hpp defines its own version of URL_COMPONENTS (why, I
do not know) in the Winapi::Wininet namespace, and by default Winapi.WinInet.hpp
dumps its content into the global namespace as well.

You need to either:

1. qualify which namespace you want to use URL_COMPONENTS from, in this case
use the global namespace:

::URL_COMPONENTS compon; // or ::URL_COMPONENTSW directly


2. add either DELPHIHEADER_NO_IMPLICIT_NAMESPACE_USE or NO_USING_NAMESPACE_WINAPI_WININET
to your project's list of precompiler conditionals. That will stop Winapi.WinInet.hpp
from dumping its content into the global namespace.

So, i tried using the scope resolution operator:
Wininet::URL_COMPONENTS compon; but other errors are take place. -
still w/o the & notion in 4th argument of InternetCrackUrlW().

You can't pass a Wininet::URL_COMPONENTS* where a ::URL_COMPONENTS* is expected.
InternetCrackUrlW() has no concept of the Wininet:: namespace. Use the
global namespace instead.

bcc32c Error] Unit1.cpp(38): no matching function for call to
'InternetCrackUrlW'
WinInet.h(767): candidate function not viable: no known conversion
from 'Wininet::URL_COMPONENTS *' (aka
'Winapi::Wininet::URL_COMPONENTSW *') to 'LPURL_COMPONENTSW' (aka
'URL_COMPONENTSW *') for 4th argument</div>
 
Exactly.  Winapi::Wininet::URL_COMPONENTS is a different type than ::URL_COMPONENTSW, 
so you can't pass a pointer to one type when a pointer to another type is 
expected.
 
<div class="jive-quote">[bcc32c Error] Unit1.cpp(41): member reference type
'Wininet::URL_COMPONENTS' (aka 'Winapi::Wininet::URL_COMPONENTSW') is
not a pointer
[bcc32c Error] Unit1.cpp(44): member reference type
'Wininet::URL_COMPONENTS' (aka 'Winapi::Wininet::URL_COMPONENTSW') is
not a pointer</div>
 
You need to use the '&' operator when passing your compon variable to InternetCrackUrlW(). 
 It is expecting a pointer, not a reference:
 

iCrack = InternetCrackUrlW(pURL.c_str(), pURL.Length(), 0, &compon);
{code}

I tried another way to use TURLComponents record *(TURLComponents
compon;)*, unfortunately it does not works and got the following
errors - still w/o the & notion in 4th argument of InternetCrackUrlW().

Same problem. You are passing a reference to one type where a pointer to
another type is expected.

Finally i've successfully compiled the code after I changed the API
structure to (LPURL_COMPONENTSW compon;).

That will compile, but will crash at runtime. LPURL_COMPONENTSW is a pointer
type, but you are not pointing it anywhere meaningful. Your memset() is
effectively making the pointer be NULL, and then you are trying to fill the
structure fields using a NULL pointer.

...but when the buton is pressed an error occurs as show in this pic.

http://postimg.org/image/6qfmviv2p/

Yup. That error is telling you that you are causing an AccessViolation due
to writing to a memory address via a NULL pointer.

--
Remy Lebeau (TeamB)
Romeo LeGagahne

Posts: 7
Registered: 1/22/16
Re: URL_COMPONENTS, TUrlComponents and InternetCrackUrl() in C++ Builder10.1  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 17, 2016 5:53 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:

Since you are calling InternetCrackUrlW() directly, you should use URL_COMPONENTSW
directly to match.

You need to either:

1. qualify which namespace you want to use URL_COMPONENTS from, in this case
use the global namespace:

::URL_COMPONENTS compon; // or ::URL_COMPONENTSW directly


2. add either DELPHIHEADER_NO_IMPLICIT_NAMESPACE_USE or NO_USING_NAMESPACE_WINAPI_WININET
to your project's list of precompiler conditionals. That will stop Winapi.WinInet.hpp
from dumping its content into the global namespace.

--
Remy Lebeau (TeamB)

Hello, Remy Lebeau

Your very detailed answer is really correct!. Now, my code is work perfectly.

Thank you very much. Your kind assistance on this are very much appreciated.

--
Romeo LeGagahne
Romeo LeGagahne

Posts: 7
Registered: 1/22/16
Re: URL_COMPONENTS, TUrlComponents and InternetCrackUrl() in C++ Builder10.1  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 17, 2016 6:34 PM   in response to: Romeo LeGagahne in response to: Romeo LeGagahne
Hello, Remy Lebeau

Like I said above, my code is compiled succesfully using ::URL_COMPONENTSW directly, but I got some error messages when I try to use the 2nd option.

I have defined DELPHIHEADER_NO_IMPLICIT_NAMESPACE_USE or NO_USING_NAMESPACE_WINAPI_WININET.

Unit1.h :
//---------------------------------------------------------------------------
#define DELPHIHEADER_NO_IMPLICIT_NAMESPACE_USE
// #define NO_USING_NAMESPACE_WINAPI_WININET
 
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:	// IDE-managed Components
	TButton *Button1;
	TButton *Button2;
	TEdit *Edit1;
	void __fastcall Button1Click(TObject *Sender);
private:	// User declarations
	void __fastcall ParseURL(const String &AURL, String &AHost, String &AResource);
public:		// User declarations
	__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif


Unit1.cpp

//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
 
#include "Unit1.h"
#include <WinInet.h>
//---------------------------------------------------------------------------
#pragma comment(lib, "WinInet.lib")
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1; 
.......


The errors messages are :

[bcc32c Error] Unit1.cpp(30): reference to 'URL_COMPONENTSW' is ambiguous
  WinInet.h(576): candidate found by name lookup is 'URL_COMPONENTSW'
  Winapi.WinInet.hpp(126): candidate found by name lookup is 'Winapi::Wininet::URL_COMPONENTSW'


I want to know how to define it precisely, Thank you very much.

--
Romeo LeGagahne

Edited by: Romeo LeGagahne on May 17, 2016 6:35 PM

Edited by: Romeo LeGagahne on May 17, 2016 6:48 PM
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: URL_COMPONENTS, TUrlComponents and InternetCrackUrl() in C++Builder10.1 [Edit]
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 17, 2016 6:49 PM   in response to: Romeo LeGagahne in response to: Romeo LeGagahne
Romeo wrote:

I have defined DELPHIHEADER_NO_IMPLICIT_NAMESPACE_USE
or NO_USING_NAMESPACE_WINAPI_WININET.

You should define them in the Project Options, like I said earlier, not in
the code itself.

Project > Options > Directories and Conditionals > Conditional defines

or

Project > Options > C++ Compiler > Directories and Conditionals > Conditional
defines

--
Remy Lebeau (TeamB)
Romeo LeGagahne

Posts: 7
Registered: 1/22/16
Re: URL_COMPONENTS, TUrlComponents and InternetCrackUrl() in C++Builder10.1 [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 17, 2016 7:13 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:

You should define them in the Project Options, like I said earlier, not in
the code itself.

Project > Options > Directories and Conditionals > Conditional defines

or

Project > Options > C++ Compiler > Directories and Conditionals > Conditional
defines

--
Remy Lebeau (TeamB)

Hello, Remy Lebeau

Works only with NO_USING_NAMESPACE_WINAPI_WININET. The use of DELPHIHEADER_NO_IMPLICIT_NAMESPACE_USE, just bring up the Project1.cpp and generates the following error:

http://postimg.org/image/q2g1lrx8h/
http://postimg.org/image/rh4aonb41/

[bcc32c Error] Project1.cpp(13): use of undeclared identifier 'Application'
[bcc32c Error] Project1.cpp(14): use of undeclared identifier 'Application'
[bcc32c Error] Project1.cpp(15): use of undeclared identifier 'Application'
[bcc32c Error] Project1.cpp(16): use of undeclared identifier 'Application'
[bcc32c Error] Project1.cpp(18): unknown type name 'Exception'
[bcc32c Error] Project1.cpp(20): use of undeclared identifier 'Application'
[bcc32c Error] Project1.cpp(26): use of undeclared identifier 'Exception'
[bcc32c Error] Project1.cpp(28): unknown type name 'Exception'
[bcc32c Error] Project1.cpp(30): use of undeclared identifier 'Application'


Btw, thank you very much.

--
Romeo LeGagahne
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: URL_COMPONENTS, TUrlComponents and InternetCrackUrl() inC++Builder10.1 [Edit] [Edit]
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 17, 2016 8:01 PM   in response to: Romeo LeGagahne in response to: Romeo LeGagahne
Romeo wrote:

Works only with NO_USING_NAMESPACE_WINAPI_WININET. The use
of DELPHIHEADER_NO_IMPLICIT_NAMESPACE_USE, just bring up the
Project1.cpp and generates the following error:

That is to be expected, since DELPHIHEADER_NO_IMPLICIT_NAMESPACE_USE effects
every VCL .hpp file, including Vcl.Forms.hpp where the global Application
object is defined. To solve that error, you would simply replace the references
to Application with Vcl::Forms::Application instead.

--
Remy Lebeau (TeamB)
Romeo LeGagahne

Posts: 7
Registered: 1/22/16
Re: URL_COMPONENTS, TUrlComponents and InternetCrackUrl() inC++Builder10.1 [Edit] [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 17, 2016 8:40 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:

That is to be expected, since DELPHIHEADER_NO_IMPLICIT_NAMESPACE_USE effects
every VCL .hpp file, including Vcl.Forms.hpp where the global Application
object is defined. To solve that error, you would simply replace the references
to Application with Vcl::Forms::Application instead.

--
Remy Lebeau (TeamB)

Hello, Remy Lebeau

I am sorry, master Remy, but there's still a problem.

This works:

Vcl::Forms::Application->Initialize();
.....


And this's failed:

.....
catch (Exception &exception)
{
  Vcl::Forms::Application->ShowException(&exception);
}
....


An errror is take place: [bcc32c Error] Project1.cpp(18): unknown type name 'Exception':

I Try :

.....
catch (Vcl::Forms::Exception &exception)
{
  Vcl::Forms::Application->ShowException(&exception);
}
 
or
 
catch (Forms::Exception &exception)
{
  Forms::Application->ShowException(&exception);
}
 
so on an on....


And Finally, the above error still occur.

Again, thank you very much.

--
Romeo LeGagahne

Edited by: Romeo LeGagahne on May 17, 2016 8:42 PM
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: URL_COMPONENTS, TUrlComponents and InternetCrackUrl()inC++Builder10.1 [Edit] [Edit] [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 18, 2016 9:06 AM   in response to: Romeo LeGagahne in response to: Romeo LeGagahne
Romeo wrote:

An errror is take place: *[bcc32c Error] Project1.cpp(18):
unknown type name 'Exception'*:

The Exception class is declared in System.SysUtils.hpp:

catch (System::Sysutils::Exception &exception)


--
Remy Lebeau (TeamB)
Romeo LeGagahne

Posts: 7
Registered: 1/22/16
Re: URL_COMPONENTS, TUrlComponents and InternetCrackUrl()inC++Builder10.1 [Edit] [Edit] [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 21, 2016 8:13 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Romeo wrote:

An errror is take place: *[bcc32c Error] Project1.cpp(18):
unknown type name 'Exception'*:

The Exception class is declared in System.SysUtils.hpp:

catch (System::Sysutils::Exception &exception)


--
Remy Lebeau (TeamB)

Hello Remy Lebeau,

It is done so well. Thank you very much for all of your assistances .

--
Romeo LeGagahne
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02