Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Need Help with C++ project

Custom Title Activated
Loyal Member
Joined
Mar 26, 2012
Messages
1,465
Reaction score
130
PHP:
HINTERNET hInternet, hFile;
DWORD rSize;
char buffer[47];
hInternet = InternetOpen(NULL, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if (hFile = InternetOpenUrl(hInternet, "http://icanhazip.com/", NULL, 0, INTERNET_FLAG_RELOAD, 0)){
    InternetReadFile(hFile, &buffer, sizeof(buffer), &rSize);
    buffer[rSize] = '\0'; 
  InternetCloseHandle(hFile);
}
char *data = "ip=", buffer;
This is the error that I receive: error c2040 char differs in leveles of indirection from 'char[47]'.
My intent is to add external IP address, Mac Address, Computer Name to char *data by something similar as char *data = "ip=" buffer "&mac=" mac "&pc_name=" pcname or something very similar. Any help would be greatly appreciated because this is new territory for myself trying to code this correctly. Thank you.
 
Watching from above
Legend
Joined
Apr 9, 2004
Messages
3,828
Reaction score
752
Does InternetReadFile expect the buffer parameter to be a pointer, or a pointer to a pointer (like you have now)? Usually I think in cases where you have to allocate memory for another method to write to, you just pass the single pointer.
 
Custom Title Activated
Loyal Member
Joined
Mar 26, 2012
Messages
1,465
Reaction score
130
I am not sure what you mean but, I am just trying to get it to read the external ip provided by that site and pass it to the next section.
 
Newbie Spellweaver
Joined
Aug 14, 2015
Messages
79
Reaction score
18
I believe

Code:
[COLOR=#0000BB]char [/COLOR][COLOR=#007700]*[/COLOR][COLOR=#0000BB]data [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#DD0000]"ip="[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]buffer[/COLOR][COLOR=#007700]; [/COLOR]


is the cause of your problem. You could try something like:

Code:
char data[60];
sprintf(&data[0], "IP: %s\0", buffer);

Also this:

Code:
[/COLOR][COLOR=#0000BB]InternetReadFile[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]hFile[/COLOR][COLOR=#007700], &[/COLOR][COLOR=#0000BB]buffer[0][/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]ARRAYSIZE(buffer)[/COLOR][COLOR=#007700], &[/COLOR][COLOR=#0000BB]rSize[/COLOR][COLOR=#007700]); [/COLOR][COLOR=#000000]
 
Custom Title Activated
Loyal Member
Joined
Mar 26, 2012
Messages
1,465
Reaction score
130
I agree that the following is the issue but, your ideas are not working. Basically it isn't getting the data from above and moving it to the variables below for use with post function of the website. I am not sure if I am making any sense. Please let me know.

char *data = "ip=", buffer;
 
[emoji848]
Legend
Joined
Dec 3, 2011
Messages
2,232
Reaction score
1,518
So first of all, expects a pointer to whatever that buffer is that you supply. Not a pointer of a pointer as mentioned by Negata.

Note that using your "buffer" array variable after the declaration is the same as using:
Code:
&buffer[0]
So it is already a pointer!

So change
Code:
InternetReadFile(hFile, &buffer, sizeof(buffer), &rSize);
to
Code:
InternetReadFile(hFile, buffer, sizeof(buffer), &rSize);
This is a false function call but it will throw an error during runtime. It's not the cause of the compiler error you get.

That being said, I believe your problem is somewhere else in your code.
You might be calling this in a function that is being declared after being called or something like that which was the case of this error in many cases already.
You need to post more code. The error is definitely not in this snippet.
 
Last edited:
Newbie Spellweaver
Joined
Aug 14, 2015
Messages
79
Reaction score
18
Please correct me if I'm wrong but won't sizeof(buffer) return 4 or 8 bytes depending on the architecture he's building? According to msdn the function will read only the amount of bytes specified in 3rd parameter.
 
[emoji848]
Legend
Joined
Dec 3, 2011
Messages
2,232
Reaction score
1,518
Please correct me if I'm wrong but won't sizeof(buffer) return 4 or 8 bytes depending on the architecture he's building? According to msdn the function will read only the amount of bytes specified in 3rd parameter.

C++ and it's nice little details.. xD This one is a bit tricky:

What you said is correct if you have a real pointer. Like:
Code:
char buffer[47];
char* bufferPtr = &buffer[0]
size_t sizeofBuffer = sizeof(buffer);
size_t sizeofBufferPtr = sizeof(bufferPtr);

Here sizeofBuffer will be 47 and sizeofBufferPtr will be 4 or 8 depending on your platform.
This is because:
sizeof is interpreted at compile time, and the compiler knows how the array was declared (and thus how much space it takes up).

The buffer rests on the Stack so it will always be of static size and the sizeof operator can determine it's end point. This most likely will not work with Heap memory (dynamically allocated)

tl;dr sizeof will work in this case
 
Newbie Spellweaver
Joined
Aug 14, 2015
Messages
79
Reaction score
18
Oh thanks for correcting me. You learn something new everyday :)
 
Custom Title Activated
Loyal Member
Joined
Mar 26, 2012
Messages
1,465
Reaction score
130
I got it figured out how to make a single string of the code that I am using but, need to pass the following to the next area. Example:
PHP:
std::cout << line_; //This information needs to be passed to the following:
curl_easy_setopt(myHandle, CURLOPT_POSTFIELDS, "HERE");

Any help would be appreciated then I will finally be set with this portion and can continue to my next section which will be very similar. Thanks guys.
 
Last edited:
Custom Title Activated
Loyal Member
Joined
Mar 26, 2012
Messages
1,465
Reaction score
130
This is what I got to at least post one of the lines:
PHP:
std::string line_;
std::ifstream file_("test.txt", ios_base::binary);
if(file_.is_open())
{
while(getline(file_, line_))
{
	if (line_.length() == 0)continue;
char acFinally[400];
DWORD nacFinally = sizeof(acFinally);
//std::cout << line_;//original that gets correct coding from the text file
file_ >> line_ >> acFinally ;
curl_easy_setopt(myHandle, CURLOPT_POSTFIELDS, acFinally);
file_.close();

I am unsure how to make it post all the lines. Any ideas?
 
Back
Top