Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


c++ crash issue - SIMPLE

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
123qwe
Newbie cheater
Reputation: 0

Joined: 26 Dec 2006
Posts: 21

PostPosted: Fri Jan 16, 2009 10:12 pm    Post subject: c++ crash issue - SIMPLE Reply with quote

hey, so i run the program, but it crashes instantly, im using visual c++ express, and it compiles with no errors, and im lost as to whats wrong with it. thanks!

It loads a password from a txt file into char *passwds. now


Code:

int nsize = 32;
char *passwds = "";
ifstream myfilea;
myfilea.open("password.txt");
myfilea.read(passwds,nsize);
myfilea.close();
Sleep(2000);
TypeStr(passwds);
Sleep(1000);
keybd_event(VK_RETURN, 0, 0, 0);
Sleep(200);
keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
Sleep(5000);


the typestr funct

Code:
void TypeStr(char *lpszString)
{
  char cChar;
  while((cChar=*lpszString++)) // loops through chars
  {
    short vk=VkKeyScan(cChar); // keycode of char
    if((vk>>8)&1){keybd_event(VK_LSHIFT,0,0,0);} // hold shift if necessary
    keybd_event((unsigned char)vk,0,0,0); // key in
    keybd_event((unsigned char)vk,0,KEYEVENTF_KEYUP,0); // key out
    if((vk>>8)&1){keybd_event(VK_LSHIFT,0,KEYEVENTF_KEYUP,0);} // release shift if necessary
  }
}
Quote:


thanks for everything! =]
Back to top
View user's profile Send private message
killersamurai
Expert Cheater
Reputation: 0

Joined: 10 Sep 2007
Posts: 197
Location: Colorado

PostPosted: Fri Jan 16, 2009 10:45 pm    Post subject: Reply with quote

You have to allocate memory for passwds. Since you are reading a static size, might as well use an array of nsize + 1.
Back to top
View user's profile Send private message
crayzbeef
Expert Cheater
Reputation: 0

Joined: 21 Jan 2007
Posts: 101

PostPosted: Sat Jan 17, 2009 3:33 am    Post subject: Reply with quote

Or actually make use of fucking STL and use a vector instead of an array.
Back to top
View user's profile Send private message
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Sat Jan 17, 2009 4:14 am    Post subject: Reply with quote

crayzbeef wrote:
Or actually make use of fucking STL and use a vector instead of an array.


I see no array.
Back to top
View user's profile Send private message MSN Messenger
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Sat Jan 17, 2009 11:07 am    Post subject: Reply with quote

crayzbeef wrote:
Or actually make use of fucking STL and use a vector instead of an array.

You're fucking stupid.

The reason is you're initializing a char* without allocating memory to it. Do

Code:

char* passwds = new char[10]; //10 should be enough you could change this if you need more.
Back to top
View user's profile Send private message
smartz993
I post too much
Reputation: 2

Joined: 20 Jun 2006
Posts: 2013
Location: USA

PostPosted: Sat Jan 17, 2009 11:42 am    Post subject: Reply with quote

_void_ wrote:
crayzbeef wrote:
Or actually make use of fucking STL and use a vector instead of an array.

You're fucking stupid.

The reason is you're initializing a char* without allocating memory to it. Do

Code:

char* passwds = new char[10]; //10 should be enough you could change this if you need more.



First useful post i've seen from you.


Also, remember if you do this..to..
Code:
delete [] passwds;




Also, why not just use strings? Easier in this case.
Back to top
View user's profile Send private message
crayzbeef
Expert Cheater
Reputation: 0

Joined: 21 Jan 2007
Posts: 101

PostPosted: Sat Jan 17, 2009 11:49 am    Post subject: Reply with quote

noz3001 wrote:
crayzbeef wrote:
Or actually make use of fucking STL and use a vector instead of an array.


I see no array.


The first post suggests using an array. Are you blind?
Back to top
View user's profile Send private message
Anden100
Grandmaster Cheater
Reputation: 0

Joined: 20 Apr 2007
Posts: 668

PostPosted: Sat Jan 17, 2009 12:15 pm    Post subject: Reply with quote

crayzbeef wrote:
noz3001 wrote:
crayzbeef wrote:
Or actually make use of fucking STL and use a vector instead of an array.


I see no array.


The first post suggests using an array. Are you blind?

Wow... i dont remember seeing one post from you, without an aggressive tone...
Back to top
View user's profile Send private message
killersamurai
Expert Cheater
Reputation: 0

Joined: 10 Sep 2007
Posts: 197
Location: Colorado

PostPosted: Sat Jan 17, 2009 12:54 pm    Post subject: Reply with quote

There isn't a need for a vector. You're not going to use its functions or change the size. Only reason to use it is if you don't want to allocate memory yourself. Using an array would be better since all you need is a buffer.

Here is an example of how I would of done it. Done in c++ (not sure if the original poster know any c)
Code:

#include <iostream>
#include <fstream>

void InitializeDynamicArray(char * addr, size_t length);

int main()
{
   char * buff;
   int buffLen;

   std::ifstream iStream("password.txt", std::ios::in);

   if (!iStream.fail())
   {
      iStream.seekg(0, std::ios::end);
      buffLen = iStream.tellg();
      iStream.seekg(0, std::ios::beg);

      if (buffLen >= 1)
      {
         buff = new char[buffLen + 1];
         InitializeDynamicArray(buff, buffLen + 1);

         iStream.read(buff, buffLen);
         iStream.close();

         std::cout << buff << std::endl;

         delete[] buff;
      }
      else
      {
         std::cout << "Nothing to read from file\n";
         iStream.close();
      }
   }
   else
      std::cout << "File not found\n";

   return 0;
}

void InitializeDynamicArray(char * addr, size_t length)
{
   for (int i = 0; i < length; i++)
      addr[i] = 0;
}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites