Eddy Dean 13 Junior Poster in Training

The second link was really helpful, I did not find that one yet.

Now I should be able to read to an different process, but there are just two problems left. How do I get the pid, how do I get the address. Getting the pid is done with parameters in all examples I've seen (including your links).

Thanks,
Arno

Eddy Dean 13 Junior Poster in Training

Hello,

I want to be able to read the memory of a process in Linux. After some googling I've read that ptrace can be used to this. The syntax of ptrace is as follows:

int ptrace(int request, pid_t pid, int addr, int data);

The first value (int request) is what function ptrace should use. For reading memory this should be PTRACE_PEEKDATA .
That won't be a problem... int data won't be a problem either. But then there is pid (process id). How am I supposed to find the process ID? Of course I do know the name and the filename of the program. The other problem is the int addr. In windows there were several tools to find this (TSearch, ArtMoney), but I don't know any of these tools for Linux (using ubuntu).

I hope some of you know a bit more about these parameters. I've done this before in Windows, and the DaniWeb community really helped me a lot back then, let's see if they can do the same for Linux ;)

Thanks in advance,
Arno

Eddy Dean 13 Junior Poster in Training
// snapshot.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <stdio.h>
#include <Tlhelp32.h>

using namespace std;


int main(int argc, char* argv[])
{
	DWORD tibiaID;
	HANDLE hProcessSnapshot = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0);
	if(hProcessSnapshot == INVALID_HANDLE_VALUE)
	{
		cout << "invalid snapshot handle" << endl;
	}

	PROCESSENTRY32 ProcessStruct;

	ProcessStruct.dwSize = sizeof(PROCESSENTRY32);

	Process32First(hProcessSnapshot, &ProcessStruct);

	if(strcmp(ProcessStruct.szExeFile, "tibia.exe") == 0) 
	{ 
	   //you have the right process.
		tibiaID = ProcessStruct.th32ProcessID;
	} 
	else 
	{ 
	   // tibia.exe is not the first process
		//looping through the other records
		while(Process32Next(hProcessSnapshot, &ProcessStruct))
		{			
			if(strcmp(ProcessStruct.szExeFile, "tibia.exe") == 0) 
			{
				//the right record has been found
				tibiaID = ProcessStruct.th32ProcessID;
				break;
			}
		}
         
	}
	cout << tibiaID;
	return 0;
}

retreives the processID of tibia.exe. You can also compare to the module name of tibia.exe.

Creating a handle from the ID is something you already know, so that won't be a problem.

Yours,
Eddy

Eddy Dean 13 Junior Poster in Training

I don't know why these errors occur, but you might want to try creating processsnapshots to find the handles.

This way is a bit harder, and it's much more code, but it might just work, right?


Greetz, Eddy

Eddy Dean 13 Junior Poster in Training

: error C2143: syntax error : missing ';' before 'constant'
: fatal error C1004: unexpected end of file found
Error executing cl.exe.


1st: You need to add a ; somewhere. I have no clue where, but it's somewhere above defining a constant

2nd: You did not include <stdafx.h>

Eddy Dean 13 Junior Poster in Training

Wouldn't shellexecute work?

ShellExecute(NULL, NULL, "epi1.htm", NULL, "C:/folderwithmovies", SW_SHOWDEFAULT);

This code can be used to open epi1.html which is located in C:/folderwithmovies.

If you're not sure about that code pay a visit to MSDN and search for shellexecute.


Greetz, Eddy

Eddy Dean 13 Junior Poster in Training
// xtea.cpp : Defines the entry point for the console application.
//

#include <stdafx.h>
#include <stdio.h>
#include <iostream>
#include <windows.h>
#include <string>

using namespace std;

unsigned char TEAKey[17] = "aaaaaaaaaaaaaaaa";
unsigned char* outbuf;




int Encrypt(unsigned char buf[], int length, unsigned char key[], unsigned char** outbuf);
unsigned char* Decrypt(unsigned char buf[], int length, unsigned char key[]);



int main(int argc, char* argv[])
{

	cout << "XTEA Key: \t \t" << TEAKey << endl;

	 unsigned char buffer[3];
	 buffer[0] = 0x01;
	 buffer[1] = 0xab;
	 buffer[2] = 0xab;

	 cout << "Original buffer:  \t"  << buffer << endl;
	 
	 int len;
	 cout << "Encrypting... \n";
	 len = Encrypt(buffer, 3, TEAKey, &outbuf);

	 cout << "Size of encrypted string: \t"<< len << endl;
	 cout << outbuf << endl;

	 unsigned char* decrypted;
	 decrypted = Decrypt(outbuf + 2, len, TEAKey);

	 cout << decrypted << endl;
	

	return 0;
}



int Encrypt(unsigned char buf[], int length, unsigned char key[], unsigned char** outbuf)
{
  if ((buf == NULL) || (key == NULL))
    return -1;

  int newsize = ((length+1)/8+1) * 8; // round up by 8
  *outbuf = new unsigned char[newsize+2];

  unsigned long delta = 0x9e3779b9;                   /* a key schedule constant */
  unsigned long sum;

  int n = 0;
  while (n < length)
  {
    sum = 0;
    unsigned long v0 = *((unsigned long*)(buf+n));
    unsigned long v1 = *((unsigned long*)(buf+n+4));

    for(int i=0; i < 32; i++)
    {
        v0 += ((v1 << 4 ^ v1 >> 5) + v1) ^ (sum + ((unsigned long*)key)[sum & 3]);
        sum += delta;
        v1 += ((v0 << 4 ^ v0 …
aeinstein commented: Nice 2C a TY & successful solution post. +10
Eddy Dean 13 Junior Poster in Training

Wat is considered spliting a string? and also if i want to manipulate each new string, i would need to split the string?

Splitting a string is if you have one string, and separate it to 2 strings at a set location.

I cannot give you an example on this now because I'm not at home. Just google for string split c++.


Greetz,Eddy

Eddy Dean 13 Junior Poster in Training
[LEFT]int strLength = str.length()-1; 
int x= 0;
while (x<strLength)
{
int   j=0;
   while (j < 4){
       newString[j] = str[x];
       cout<< newString[j];
      j++;
    }
cout << " ";
    x++;
}

Should work. This is not really splitting the string! It's just outputting the string with spaces in it.

Greetz, Eddy[/LEFT]

Eddy Dean 13 Junior Poster in Training

It might sound harsh, but we're (at least, Me) are not interested in how urgent this is for you.

Next time you post please use proper English, punctuation etcetera. Also choosing a proper title would help a lot. The title you used doesn't give any information at all. You're not giving any information about what the problem is.

The only thing you do is giving us a piece of code, without even telling what's wrong, and then expecting us to locate the problem and solve it.

I know it might not be your fault that your English isn't perfect, but I think punctuation is the same in all languages (Okay, most of the languages).

Don't think I'm mad at you, or dislike you. It's just several things that need to be corrected before you should expect to receive any usefull input from us.

I'll give you just an example to show how confusing it can be to read something without punctuation:

it doesn't goes back again to accept another choice.unlike when i'm inputting a number greater than and less than my choices(1-5) it goes back again to accept another choice

Now please re-read this sentence, and see if you can figure out what you mean with that. I can't really. I have no clue what you're trying to say in that sentence.


Yours,
Eddy

Rashakil Fol commented: You're awesome. +3
Eddy Dean 13 Junior Poster in Training

Have you actually looked through your code, line by line (possibly while debugging)? How about these lines, in the encryption function:

// put length back in the package 
(*outbuf)[0] = newsize & 0xFF;
(*outbuf)[1] = (newsize >> 8) & 0xFF;

You seem to completely ignore that the first two bytes of the output buffer are not encrypted data when you go to decrypt:

unsigned long v0 = *((unsigned long*)(buf+n));
unsigned long v1 = *((unsigned long*)(buf+n+4));
//try
unsigned long v0 = *((unsigned long*)(buf+n+2));
unsigned long v1 = *((unsigned long*)(buf+n+6));

And it seems like you should be storing the original length of the buffer, so when you decrypt you can ignore the last x garbage bytes if the original buffer size wasn't a multiple of 8.

Wow... That's true, I must've totally overseen it. This is because this project involves data communication. Usually it will read the size of the packet, and then decrypt the rest. This might indeed have caused my the problem. Removing the lines that add the length back in to the packate won't help anyway, so even though you're probabl right about this, it is not the solution I was hoping for.

I've also noticed that using several variable types might also cause troubles because I'm using both MBS and SBS. The problem is that I don't know how to solve this. Trowing around with variables never been my strongest point, and this is "trowing around with varables"²

So: The problem is still there, even if I'm the …

Eddy Dean 13 Junior Poster in Training

What I want to achieve:
I want to be able to encrypt and decrypt data with an XTEA algorithm. The key will get loaded from an external program.

What am I trying to do in the given code:
In the code I am trying to make a buffer, encode it and decode it and see if it has changed (If the buffer is the same as the output).

Program specifications:
At the moment all code I have is what is posted above. As soon as it's finished I will use this encryption algorithm to let 2 programs communicate using encrypted data.

Where I think the problem is:
The encryption. The encryption-output is smaller then the start-buffer.


Of course you're not asking too much, but I have a feeling that I'm not asking too much either, but still having only one member actively helping with problem (obviously ~S.O.S~) which might've caused my annoyed attitude before. My apologies.

'
Greetz, Eddy

What is my problem:
The buffer I start with is not the same as the output

Eddy Dean 13 Junior Poster in Training

That's the same as my code, except that my code splits it into 8-byte blocks... Thanks for your reply, but unfortunately it didn't help.


Greetz, Eddy

Eddy Dean 13 Junior Poster in Training

I still didn't fix it. The decrypted string is not equal to the buffer I start with.

Anyone, please help me. I posted the code in above post.


Greetz, Eddy

Eddy Dean 13 Junior Poster in Training

I believe that you need to put 0x in front of a number if it needs to be hexadecimal (or was it $??)


Greetz, Eddy

Eddy Dean 13 Junior Poster in Training

I am really sorry that you don't really feel at home on this nice forum. I do not know any of your posts, but I do believe that you could be a bit more precise with your spelling, punctuation etcetera.

I know not everyone is good at English, but if you show us that you don't even want to try (as shown in WaltPs post) it looks like you only want help, without doing too much yourselves.

Noone thinks you're a complete idiot, and if some people overreact everything may seem worse then it is.

Take my advice, and re-read your post for spelling errors and punctuation before you post. It will help to get an answer that's usefull.


Greetz, Eddy

Eddy Dean 13 Junior Poster in Training

EDIT: It seems like Micko was just a minute too fast. He is right. cin.get() won't work in C.

--------------------old post----------------------
Then add cin.get() at the end of your code (before the return, of course). This will pause your program so you get more time to read the output. It will wait for you to press enter

Eddy Dean 13 Junior Poster in Training

Please get a new compiler... Dev-C++ maybe (search google for dev-cpp borland). It's loads better.


Greetz, Eddy

Eddy Dean 13 Junior Poster in Training

Because you don't have the program I load the key from, XTEAKey doesn't contain a key.

A key I get is ~9p<›¸*%-Zvæ7‘ .

But as you probably notice my computer can't handle some of these characters.

Let's all use aaaaaaaaaaaaaaaa (16*a) as key, okay?

New source (without the key-thingy):

// xtea.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <windows.h>

using namespace std;

unsigned char TEAKey[130] = "aaaaaaaaaaaaaaaa";
HANDLE processHandle;
unsigned char* outbuf;
unsigned char* outbuffer;




/*void GetEncryptionKey();*/
int Encrypt(unsigned char buf[], int length, unsigned char key[], unsigned char** outbuf);
unsigned char* Decrypt(unsigned char buf[], int length, unsigned char key[]);



int main(int argc, char* argv[])
{
	HWND hWnd; DWORD processId;
	hWnd = FindWindow("tibiaclient", NULL);	
	GetWindowThreadProcessId(hWnd, &processId);
	processHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId);
	/*GetEncryptionKey();*/
	//cout << "Starting to get XTEA key" << endl;
	cout << "XTEA Key: \t \t" << TEAKey << endl;

	 char buffer[3];
	 buffer[0] = 0x11;
	 buffer[1] = 0x05;
	 buffer[2] = 0x14;


	 cout << "Characters put inside buffer \n";
	 cout << "Original buffer:  \t"  << buffer[0] << buffer[1] << buffer[2] << buffer[3] << endl;
	 unsigned char* orig;
	 orig = (unsigned char*)buffer;
	 cout << "orig casted: \t\t" << orig << endl;
	 //std::cout << packet << endl;
	 
	 int len;
	 cout << "Encrypting... \n";
	 len = Encrypt((unsigned char*)buffer, 3, (unsigned char*)TEAKey, &outbuf);

	 cout << "Size of encrypted string: \t"<< len << endl;
	

	 unsigned char* decrypted;
	 //decrypted = Decrypt(outbuf, len, TEAKey);
	 //cout << "Decrypted: \t \t" << &decrypted …
Eddy Dean 13 Junior Poster in Training

You're right, but it does not fix the problem.

Thanks anyway,
Eddy

Eddy Dean 13 Junior Poster in Training

Hello everyone,

I am trying to get an XTEA algorithm to work. I read the key from another process of which I'm sure it has a valid key at a specific location in memory.

My encryption algorithm seemed to work, but when I tested it by making a buffer, encrypting and then decrypting I found out that it did not match the buffer.

I also hate the amount of char[3] to unsigned char* etc, etc conversions. I'm not rather good at trowing around variables so this really is hell to me.

Several things I'm sure of:
The key has 16 characters
The size of the packets gets rounded up to 8 correctly
It does not crash
As long as the key stays the same so do the packets (buffer, encrypted and decrypted)
I am using MSVC++ on Windows XP

My code so far:

// xtea.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <windows.h>

using namespace std;

unsigned char TEAKey[130];
HANDLE processHandle;
unsigned char* outbuf;
unsigned char* outbuffer;

#define ENCRYPT_KEY			0x0074B1A0 //The XTEA Key that is used for encrypting the packets



void GetEncryptionKey();
int Encrypt(unsigned char buf[], int length, unsigned char key[], 

unsigned char** outbuf);
unsigned char* Decrypt(unsigned char buf[], int length, unsigned char key[]);



int main(int argc, char* argv[])
{
	HWND hWnd; DWORD processId;
	hWnd = FindWindow("tibiaclient", NULL);	
	GetWindowThreadProcessId(hWnd, &processId);
	processHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId);
	GetEncryptionKey();
	cout …
Eddy Dean 13 Junior Poster in Training

That worked, thanks a lot!

Don't know why I didn't figure this out with plain logic... Why would you want to clear something before you even use it?


Thanks a lot,
Eddy

Eddy Dean 13 Junior Poster in Training

Sorry, I didn't quite catch that.

Did you take a look at my code?
It starts up the WSA-thing, then it cleans, then it starts the socket, which gives an error.

Greetz, Eddy

Eddy Dean 13 Junior Poster in Training

This was supposed to be an edit, but I did not find an edit button, my apologies.

I called WSAGetLastError and it returned 10093.

According to MSDN error 10093 means:

WSANOTINITIALISED
10093	
Successful WSAStartup not yet performed.
Either the application has not called WSAStartup or WSAStartup failed. The application may be accessing a socket that the current active task does not own (that is, trying to share a socket between tasks), or WSACleanup has been called too many times.

As a matter of fact I have performed WSAStartup, and it does not return an error!

//starting up the winsock library, error checking
    if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0) {
        cout << "WSAStartup failed.\n";
        exit(1);
    }

It never outputs that the startup has failed, so I don't believe that's the problem...


Yours,
Eddy

Eddy Dean 13 Junior Poster in Training

Hello everyone,

I am trying to create a "proxy" for a program. I will try to explain how I am going to do that.

The program I want to write a proxy for sends and receives data to/from a server. The IP and port the client connects to is somewhere in the memory, and I know how to change that.

I will write the memory of the client to connect to port 1000 (just a random number...) on localhost.

like this:
[IMG]http://img92.imageshack.us/img92/6016/proxyexamplerz4.png[/IMG]


Well, I hope it is clear now what I want to do. The problem is that I can't get through a very basic stadium: creating the sockets.

I've tried about every tutorial, snippet, I read many guides about sockets, the winsock functions, but I keep getting errors.

The worst error is if I try #include <winsock2.h> I have included:

#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <stdio.h>
#include <winsock2.h>

and linked:

WSOCK32.LIB MPR.LIB

The including of winsock2.h adds 58 errors and 11 warnings to the debug window.

--------------------Configuration: socktest - Win32 Debug--------------------
Compiling...
socktest.cpp
c:\program files\microsoft visual studio\vc98\include\winsock2.h(99) : error C2011: 'fd_set' : 'struct' type redefinition
c:\program files\microsoft visual studio\vc98\include\winsock2.h(134) : warning C4005: 'FD_SET' : macro redefinition
        c:\program files\microsoft visual studio\vc98\include\winsock.h(83) : see previous definition of 'FD_SET'
c:\program files\microsoft visual studio\vc98\include\winsock2.h(143) : error C2011: 'timeval' : 'struct' type redefinition
c:\program files\microsoft visual studio\vc98\include\winsock2.h(199) : error C2011: 'hostent' : 'struct' type redefinition
c:\program files\microsoft …
Eddy Dean 13 Junior Poster in Training

If the list to sort will only consist of integers and you know the smallest and the largest value you can also use counting sort. Rather fast, very easy.


Greetz, Eddy

Eddy Dean 13 Junior Poster in Training

Wikipedia has a whole page dedicated to sorting algorithms:

http://en.wikipedia.org/wiki/Sorting_algorithm

Snippet taken from the Dutch wikipedia, "invoer" is the array you want to sort and lengte is the number of values in the array

void bubblesort(int invoer[],int lengte){
  int i,j,tijdelijk;
  for(j=0;j<lengte-1;j++){
    for(i=1;i<lengte-j;i++){
      if(invoer[i-1]>invoer[i]){
        tijdelijk=invoer[i];
        invoer[i]=invoer[i-1];
        invoer[i-1]=tijdelijk;
      }
    }
  }
}

note that this is a really in-efficient way of sorting. I once executed it on a 14000 number array. Took several minutes.

this:

void straightselection(int invoer[],int lengte){
  int i,j,kleinste,tijdelijk;
  for(j=0;j<lengte-1;j++){
    kleinste=j;
    for(i=j+1;i<lengte;i++){
      if(invoer[i]<invoer[kleinste]) kleinste=i;
    }
    if(kleinste!=j){
      tijdelijk=invoer[j];
      invoer[j]=invoer[kleinste];
      invoer[kleinste]=tijdelijk;
    }
  }
}

is also taken from the Dutch wikipedia. It is a straight selection sort algorithm. It looks for the smallest item in the array and puts it on the end of the array. You might want to improve this algorithm by letting it search for the smallest and the largest at the same time.


Goodluck,
Eddy

Eddy Dean 13 Junior Poster in Training

I suggest you use the search function next time.

http://www.daniweb.com/techtalkforums/thread50205.html


Greetz, Eddy

Eddy Dean 13 Junior Poster in Training

EDIT:
I did it. String to const char* conversion can be done with string.c_str() Thanks for your help Dave! I really appreciate it

Mwah... Looking pretty good... I'll try it.

Thanks for your reply.

I'm still having problems converting a string to a const char*.


Thanks again,
Eddy
Eddy Dean 13 Junior Poster in Training

Hello everyone,

I downloaded the source of an internet file and need to filter a specific part of it.

I know how the string::size_type position = Line.find("World:</TD><TD>"); function works, but this only tells me where the data I am looking for is located (the data is after "World:</TD><TD>").

I want to have everything that is behind it in a different string, until the "<" gets reached.

Example:

</TR><TR BGCOLOR=#F1E0C6><TD>World:</TD><TD>Blahblah</TD></TR>

is loaded into my string "Line".
I run my sorting thing and it should return "Blahblah" in an other string.

It is an std::string type variable.

I am also looking for a way to convert from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'const
char *'

(at least, the error message says so, it is just a string to const char* conversion)


Thanks in advance.
Eddy

Eddy Dean 13 Junior Poster in Training

I still don't really get what you mean with the database. Is it an SQL database you need to put it to (or another type of database)? Or do you just mean an array(table) inside your own program?


Greetz, Eddy

Eddy Dean 13 Junior Poster in Training

Hi all,

I'd posted this problem previously but in the wrong place..:)..Hopefully, I can get the answer from this thread. I'm a newbie in C..Right now, I have to write a code to read a text file and then insert all the info inside that text file into database. Should anyone have a simple sample of it, maybe you can share with me in order for me to learn on how to do it.

Thanks in advance

// reading a text file
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main () {
  string line; //this will contain the data read from the file
  ifstream myfile ("example.txt"); //opening the file.
  if (myfile.is_open()) //if the file is open
  {
    while (! myfile.eof() ) //while the end of file is NOT reached
    {
      getline (myfile,line); //get one line from the file
      cout << line << endl; //and output it
    }
    myfile.close(); //closing the file
  }
  else cout << "Unable to open file"; //if the file is not open output <--

  return 0;
}

I don't really get what you mean by sending it to a database, but this is the file-reading part


Greetz, Eddy


EDIT:
Oh wait, you sayd "C", did you mean C or C++? If it's C above code probably won't work.
If you're really doing C then I suggest you switch to C++ anyway ;)

Eddy Dean 13 Junior Poster in Training

Or better still get accustomed to the dot net framework, and learn c#. You can make quick GUIs wicked fast.

C# is decompilable, so it isn't really usefull for bigger projects, unless it's open-source anyway.

I have absolutely no clue about MFC tutorials, so I can't help you, sorry

Eddy Dean 13 Junior Poster in Training
#include <windows.h>
#include <iostream>
int main(){
POINT c;
GetCursorPos(&c);
std::cout<<c.x<<", "<<c.y;
}

is enough...

7 lines

You were wrong with your estimation 10-15 lines!

Some compilers might not agree that it does not have a return value. I had to include StdAfx.h because I used visual c++.


Greetz, Eddy

Eddy Dean 13 Junior Poster in Training
char* url;
	string sUrl;


	HINTERNET hINet, hFile;
	hINet = InternetOpen("InetURL/1.0", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 );
	if ( !hINet )
	{
		return false;
	}
	//http://www.tibia.com/statistics/?subtopic=highscores&world=Aldora&list=magic&page=10
	int Page = 0;
	while(Page < 12)
	{
	sUrl+="http://www.tibia.com/statistics/?subtopic=highscores&world=";
	sUrl+=Server;
	sUrl+="&list=";
	sUrl+=Skill;
	sUrl+="&page=";
	sUrl+=Page;
	Page+=1;

	strcpy(url, sUrl.c_str());
		cout << url << endl;
 
		
		hFile = InternetOpenUrl( hINet, url, NULL, 0, 0, 0 );
		if ( hFile )
--------------------Configuration: TibiaName - Win32 Debug--------------------
Compiling...
TibiaName.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\TibiaName\TibiaName.cpp(170) : warning C4700: local variable 'url' used without having been initialized
Linking...

TibiaName.exe - 0 error(s), 1 warning(s)

and craaaaaash... The program crashes without returning any data.
I didn't find the error yet by breakpoints. I will try to continue the search..
Thanks anyway

Greetz, Eddy

Eddy Dean 13 Junior Poster in Training

Hello,

I've had some problems converting a string into a char. I've tried many, many things, but it didn't seem to work.

I'll post the code below:

char filename[1024];
	char* url;
	string sUrl;


	HINTERNET hINet, hFile;
	hINet = InternetOpen("InetURL/1.0", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 );
	if ( !hINet )
	{
		return false;
	}
	//http://www.tibia.com/statistics/?subtopic=highscores&world=Aldora&list=magic&page=10
	int Page = 0;
	while(Page < 12)
	{
	sUrl+="http://www.tibia.com/statistics/?subtopic=highscores&world=";
	sUrl+=Server;
	sUrl+="&list=";
	sUrl+=Skill;
	sUrl+="&page=";
	sUrl+=Page;
	Page+=1;

	url = sUrl.c_str();
		cout << url << endl; 
		
		hFile = InternetOpenUrl( hINet, (char*)sUrl, ULL, 0, 0, 0 );
                  //The rest of the loop, no troubles here.

As you can see, I'm making a string that will contain the URL, I place the URL in it and then want to convert it to a char*.

I really tried about everything.

The URL doesn't neccesarely have to be a string, but I thought that would be the easiest way.

The errors that I get are:

Compiling...
TibiaName.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\TibiaName\TibiaName.cpp(169) : error C2440: '=' : cannot convert from 'const char *' to 'char *'
        Conversion loses qualifiers
C:\Program Files\Microsoft Visual Studio\MyProjects\TibiaName\TibiaName.cpp(173) : error C2440: 'type cast' : cannot convert from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'char *'
        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Error executing cl.exe.

TibiaName.exe - 2 error(s), 0 warning(s)

line 169 is url = sUrl.c_str(); and line 173 is hFile = InternetOpenUrl( hINet, (char*)sUrl, ULL, 0, 0, 0 );

Eddy Dean 13 Junior Poster in Training
#include <iostream>
#include <string>


int main()
{
string name;
name="mark";
     cout<<name;
     return 0;
}
Eddy Dean 13 Junior Poster in Training

I don't think you'll be able to do this with 2 weeks of C++ experience. Of course I have no idea about how good you are at C++, but I think it's too advanced.

You should search www.msdn.com, there are several APIs that will handle mouse-things.

There is also something to record mouse movements, I don't really remember much of it.

codeproject has a mouse-macro recorder with source, you might want to check it.

Goodluck,
Eddy

Eddy Dean 13 Junior Poster in Training

Don't you think you need a Main() function?

Eddy Dean 13 Junior Poster in Training

If you're planning on making rather simple programs Visual Basic is nice too. Designing a gui is really easy and to put code "under" a button is really easy.

Still I always use C++, GUI of no GUI. Designing a gui may take a while, but IMHO it's worth the effort.

I never used Java though, so I have no idea if it's good or bad...

Greetz, Eddy

Eddy Dean 13 Junior Poster in Training

You pretty much posted the whole code. I don't think it's usefull to post the full source of my program because I've got 250 lines so far (I don't know if comment is counted too, can anyone verify this?)

I guess that this project will be ~500 lines when it's finished.

Greetz,Eddy

Eddy Dean 13 Junior Poster in Training

Winsock hooking.

You make 2 programs, an easy one, it injects the DLL into iexplore.exe, and a pretty complicated one. It hooks the WinSock functions of iexplore.exe and saves/outputs the data.

There is a thread at the moment about injecting DLLs into applications.
www.madshi.net has a api-hooking library, you might want to use that.

Goodluck,
Eddy

Eddy Dean 13 Junior Poster in Training

huhhwwhaddayado?! (translation: Huh? What did you do?)

It works! It really does!

Thanks a million!


Greetz, Eddy

Eddy Dean 13 Junior Poster in Training

Sorry if I didn't explain well. I'm not getting any errors while compiling or building. The buffer was just empty so I added error checking , like if(!bSendRequest){ printf("Error while sending request \n"); return 0;} now when I run the program I get "Error while sending request" as output to the command.

This made me think that somewhere went wrong at that function.


Greetz, Eddy

Eddy Dean 13 Junior Poster in Training

Making GUIs in C++ is rather complicated. I suggest you try to download a tutorial about it. There are plenty of tutorials about GUI making out there.

If you're willing to pay http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_21902809.html is pretty nice.


http://www.rohitab.com/discuss/lofiversion/index.php/t11408.html


Excuse me if I sound a bit rude, but next time please google before you post.


Greetz, Eddy

Eddy Dean 13 Junior Poster in Training

This is what I've got so far. As you can see I added some error checking and the errors are at HttpSendRequest(hHttpFile, NULL, 0, NULL, 0); I'll post the full source here:

// openmic.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include <windows.h>
#include <wininet.h>


int main(int argc, char* argv[])
{
	// Open Internet session.
HINTERNET hSession = ::InternetOpen("My app name",
                                    PRE_CONFIG_INTERNET_ACCESS,
                                    NULL, 
                                    INTERNET_INVALID_PORT_NUMBER,
                                    0) ;
if(!hSession){printf("Error while opening the internet session \n"); return 0;}

// Connect to www.microsoft.com.
HINTERNET hConnect = ::InternetConnect(hSession,
                                    "http://www.microsoft.com",
                                    INTERNET_INVALID_PORT_NUMBER,
                                    "",
                                    "",
                                    INTERNET_SERVICE_HTTP,
                                    0,
                                    0) ;
if(!hConnect){printf("Error while connecting to the server \n"); return 0;}
// Request the file /MSDN/MSDNINFO/ from the server.
HINTERNET hHttpFile = ::HttpOpenRequest(hConnect,
                                     NULL,
                                     "/MSDN/MSDNINFO/",
                                     HTTP_VERSION,
                                     NULL,
                                     0,
                                     INTERNET_FLAG_DONT_CACHE,
                                     0) ;
if(!hHttpFile){printf("Error while requesting the file \n"); return 0;}

// Send the request.
BOOL bSendRequest = ::HttpSendRequest(hHttpFile, NULL, 0, NULL, 0);

if(!bSendRequest){ printf("Error while sending request \n"); return 0;}

// Allocate a buffer for the file.   
char* buffer = new char[50000] ;

// Read the file into the buffer. 
DWORD dwBytesRead ;
BOOL bRead = ::InternetReadFile(hHttpFile,
                                buffer,
                                3000, 
                                &dwBytesRead);
// Put a zero on the end of the buffer.
buffer[dwBytesRead] = 0 ;

if(!bRead) buffer = "Nothing has been loaded";
// Close all of the Internet handles.
::InternetCloseHandle(hHttpFile); 
::InternetCloseHandle(hConnect) ;
::InternetCloseHandle(hSession) ;


printf("buffer: %s", buffer);
	return 0;
}

@everyone: thanks for your support, you've been very helpfull.


Greetz, Eddy

Eddy Dean 13 Junior Poster in Training

You're right. sizeof() returns the array size, not the amount of characters in an array, and strlen only works for strings. You could of course convert the char to a string, but that's not the point here.

#include "stdafx.h"
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
	char singular[6];
	cout << "Insert a word with max 6 characters to make plural: ";
	cin >> singular;
	char plural[7];
	sprintf(plural, "%ss", singular);
	cout << "The plural of " << singular << " is: " << plural << endl;
	return 0;
}

works fine too...

WARNING: INSERTING MORE THEN 6 CHARACTERS WILL RESULT IN A CRASH!


Greetz, Eddy

Eddy Dean 13 Junior Poster in Training

I think you need to look at strlen .

I don't think that really matters. strlen is for strings only I guess, sizeof() can give the size of multiple variable types (Never really tried which types).

Anyway, he's got it working.


@the thread starter, to expand your program and learn a bit more you might also want to add support for words with more characters and don't add an "s" if the last character (before the /0) already is "s".

Greetz, Eddy

Eddy Dean 13 Junior Poster in Training

Hello everyone,

I 've been looking for a solution for this problem for some time now but I don't seem to figure it out.

I want to download the source of a web page (the HTML source). I found several API function that have to do something with internet and downloading for example InternetOpen, InternetOpenUrl .

This didn't work. I tried almost everything but it wouldn't compile.

I found this code on MSDN:

int main(int argc, char* argv[])
{
	HINTERNET hNet = ::InternetOpen("MSDN SurfBear",
                                PRE_CONFIG_INTERNET_ACCESS,
                                NULL,
                                INTERNET_INVALID_PORT_NUMBER,
                                0) ;

HINTERNET hUrlFile = ::InternetOpenUrl(hNet,
                                "http://www.microsoft.com",
                                NULL,
                                0,
                                INTERNET_FLAG_RELOAD,
                                0) ;

char buffer[10*1024] ;
DWORD dwBytesRead = 0;
BOOL bRead = ::InternetReadFile(hUrlFile,
                                buffer,
                                sizeof(buffer),
                                &dwBytesRead);

::InternetCloseHandle(hUrlFile) ;

::InternetCloseHandle(hNet) ;
	return 0;
}

It keeps giving me the following errors:

--------------------Configuration: internetopen - Win32 Debug--------------------
Linking...
internetopen.obj : error LNK2001: unresolved external symbol __imp__InternetCloseHandle@4
internetopen.obj : error LNK2001: unresolved external symbol __imp__InternetReadFile@16
internetopen.obj : error LNK2001: unresolved external symbol __imp__InternetOpenUrlA@24
internetopen.obj : error LNK2001: unresolved external symbol __imp__InternetOpenA@20
Debug/internetopen.exe : fatal error LNK1120: 4 unresolved externals
Error executing link.exe.

internetopen.exe - 5 error(s), 0 warning(s)

One project I downloaded does work. A bit. It downloads the first several lines of the source and then just outputs fffffffffffffffffffffffffffffffff (it the buffer gets filler with ff-s after the first lines of source).

Also this is an MFC project, and I prefer not using MFC.

I'll post the MFC code below:

void CMFCinternetDlg::OnButton1() 
{
	// …
Eddy Dean 13 Junior Poster in Training

Taken from MSDN:

sizeof Operator  


Yields the size of its operand with respect to the size of type char.

Wouldn't this be usefull? It would probably save you a loop. It's also usefull to check if the user entered a 6-digit word.

Anyway, you made it, congratulations.

Greetz, Eddy