Hey there. It's been awhile since I posted in the VB6 area. :bigyello:
I've recently been doing some heavy duty C++ programming lately, mostly in the DirectX area, and recently got into Winsock. So after getting an awesome server to client chit chat program through the console window, I was wanting to attempt this in VB6 just for kicks. However, I ran into an api that seems to have little to no results in Google. And that is getaddrinfo(). All the other examples in VB6 I ran into have been using gethostbyname() instead which have been deprecated, and has been widely recommended that you use getaddrinfo() instead. Anyways I don't wanna go to far into talking about winsock programming or this thread will end up moved to the networking thread. My concern is the conversion. How the C++ api getaddrinfo() is, is setup like this:
Now _In_opt_ would make it ByVal and _Out_ would be ByRef after researching that, however we got a lot of pointers going on here. PCSTR would be a pointer to a constant string, pHints is a pointer to the structure ADDRINFO along with ppResult. However online, the only time I ever saw getaddrinfo() declared in VB was from someone posting a problem in a forum, and he had it setup differently, and in my opinion totally wrong which is why it wasnt working for him:
http://www.solveerrors.com/forums/us...vb6-239905.asp
First of all, his ADDRINFO datatype is missing 2 declarations which the API is dependent on, along with another structure. But when I declare it, I obviously can't declare a variable as the structure its within in vb6:
Ok thats problem one that I'll need help in the conversion process to get the API to function properly.
Secondly is the API itself. He has it declared as this:
I cant but feel this is also wrong, cause the original C++ version consists of all pointers, whether its to a string or structure. And you also cant ByVal Hints As AddrInfo cause you are using a structure and VB6 wont allow it. Youll end up with an error saying "User Defined Type cannot be passed through ByVal." So I have this setup for the API which is kind of the same but doubt its correct, and I cant find anything else on it through Google:
When the API is used in C++ it looks something like this:
Which works great. And NULL if you put your mouse over it in Visual Studio shows #define NULL 0;. Now for the VB6 version, he did it differently which is why it failed for him, not to mention his string has a number instead of a string:
Now in my program I wrote in VB6, I did it differently:
And there was no 11003 and it passed, buuuuuuuut.....there was no result output because it remained 0 for everything. I saw this when I printed em out:
Which leads to the conclusion that something is setup wrong either in the API itself, or the user defined type due to the missing declaration, or both! How would I go about setting it up correctly so I can get getaddrinfo() working properly in VB6 since there is a lack of information regarding the API?
Hopefully I didnt make it too confusing for yall. :bigyello:
I've recently been doing some heavy duty C++ programming lately, mostly in the DirectX area, and recently got into Winsock. So after getting an awesome server to client chit chat program through the console window, I was wanting to attempt this in VB6 just for kicks. However, I ran into an api that seems to have little to no results in Google. And that is getaddrinfo(). All the other examples in VB6 I ran into have been using gethostbyname() instead which have been deprecated, and has been widely recommended that you use getaddrinfo() instead. Anyways I don't wanna go to far into talking about winsock programming or this thread will end up moved to the networking thread. My concern is the conversion. How the C++ api getaddrinfo() is, is setup like this:
Code:
typedef struct addrinfo {
int ai_flags;
int ai_family;
int ai_socktype;
int ai_protocol;
size_t ai_addrlen;
char *ai_canonname;
struct sockaddr *ai_addr;
struct addrinfo *ai_next;
} ADDRINFOA, *PADDRINFOA;
int WSAAPI getaddrinfo(
_In_opt_ PCSTR pNodeName,
_In_opt_ PCSTR pServiceName,
_In_opt_ const ADDRINFOA *pHints,
_Out_ PADDRINFOA *ppResult
);
http://www.solveerrors.com/forums/us...vb6-239905.asp
First of all, his ADDRINFO datatype is missing 2 declarations which the API is dependent on, along with another structure. But when I declare it, I obviously can't declare a variable as the structure its within in vb6:
vb Code:
Public Type sockaddr sin_family As Integer sin_port As Integer sin_addr As Long sin_zero(1 To 8) As Byte End Type Public Type addrinfo 'typedef struct addrinfo { ' int ai_flags; ' int ai_family; ' int ai_socktype; ' int ai_protocol; ' size_t ai_addrlen; ' char *ai_canonname; ' struct sockaddr *ai_addr; ' struct addrinfo *ai_next; '} ADDRINFOA, *PADDRINFOA; ai_flags As Long ai_family As Long ai_socktype As Long ai_protocol As Long ai_addrlen As Long AI_CANONNAME As String ai_addr As sockaddr 'ai_next As addrinfo '<----- not allowed in vb6 End Type
Ok thats problem one that I'll need help in the conversion process to get the API to function properly.
Secondly is the API itself. He has it declared as this:
vb Code:
Private Declare function GetAddrInfo Lib "ws2_32.dll" Alias "getaddrinfo" ( _ ByVal NodeName As String, _ ByVal ServName As String, _ Hints As AddrInfo, _ res As AddrInfo) As Long
I cant but feel this is also wrong, cause the original C++ version consists of all pointers, whether its to a string or structure. And you also cant ByVal Hints As AddrInfo cause you are using a structure and VB6 wont allow it. Youll end up with an error saying "User Defined Type cannot be passed through ByVal." So I have this setup for the API which is kind of the same but doubt its correct, and I cant find anything else on it through Google:
vb Code:
'The getaddrinfo function provides protocol-independent translation from an ANSI host name to an address. Public Declare Function getaddrinfo Lib "ws2_32.dll" (ByVal pNodeName As String, ByVal pServiceName As String, pHints As addrinfo, ppResult As addrinfo) As Long
When the API is used in C++ it looks something like this:
C++ Code:
#define DEFAULT_PORT "3504" int iResult = 0; int Setup_Server() { iResult = getaddrinfo(NULL, DEFAULT_PORT, &hints, &result); if ( iResult != 0 ) { cout << "getaddrinfo failed with error: " << iResult << endl; WSACleanup(); return 1; } }
Which works great. And NULL if you put your mouse over it in Visual Studio shows #define NULL 0;. Now for the VB6 version, he did it differently which is why it failed for him, not to mention his string has a number instead of a string:
vb Code:
iRet = GetAddrInfo(sHost, 0, Hints, res)
Now in my program I wrote in VB6, I did it differently:
vb6 Code:
iResult = getaddrinfo("", DEFAULT_PORT, Hints, result)
And there was no 11003 and it passed, buuuuuuuut.....there was no result output because it remained 0 for everything. I saw this when I printed em out:
Code:
Print result.ai_family
Print result.ai_socktype
Print result.ai_protocol
'Output
'0
'0
'0
Hopefully I didnt make it too confusing for yall. :bigyello: