Hi Wormgrinder, welcome.
You have most of what is needed in your program to use the function. But if you read the MS documentation a little closer and you should see the details needed to call the function:
- dwStructSize must be set to size of structure
- if buffer and size are both zero, nothing return
- if buffer = NULL and size is non-zero ... see the docs -- this method didn't work for me
- if buffer is allocated and size non-zero, some information is copied -- this did work for me
URL_COMPONENTS is already declared in win headers, so you don't need to declare this.
Yeah, the error message is misleading...
See
operator precedence with respect to *lpUrlComponents.lpszHostName
The member access '.' operator takes precedence over the the value of '*' operator
lpUrlComponents is a pointer and also lpUrlComponents->lpszHostName is a pointer,
So should instead be:
*lpUrlComponents->lpszHostName
or
*(*lpUrlComponents).lpszHostName
Code: Select all
#define UNICODE
#include once "windows.bi"
#include once "win\wininet.bi"
#define allocLPWSTR( n ) cast( LPWSTR, callocate((n + 1) * SizeOf(WString)))
#define freeLPWSTR( s ) if s then: deallocate s: end if
Dim sTestUrl As String = "https://www.freebasic.net/"
Dim lpszTestUrl As WString Ptr = allocLPWSTR( len(sTestUrl) )
*lpszTestUrl = sTestUrl
Print *lpszTestUrl
Dim lpUrlComponents As LPURL_COMPONENTS = New URL_COMPONENTS
with *lpUrlComponents
'' dwStructSize must be set to size of structure
.dwStructSize = sizeof( URL_COMPONENTS )
'' items to be returned must be allocated a buffer and max length
.lpszHostName = allocLPWSTR( 1000 )
.dwHostNameLength = 1000
end with
InternetCrackUrl(lpszTestUrl, Len(*lpszTestUrl), ICU_DECODE, lpUrlComponents)
Print *lpUrlComponents->lpszHostName
freeLPWSTR(lpUrlComponents->lpszHostName)
freeLPWSTR(lpszTestUrl)
Delete lpUrlComponents
Sleep