mitrmkar 1,056 Posting Virtuoso

I think you need to have a virtual destructor (currently you are observing undefined behaviour).

mitrmkar 1,056 Posting Virtuoso

If you are unhappy with the SHBrowseForFolder(), perhaps have a look at the Show Shell common file dialog sample from MSDN.

In your hook procedure, you need to use the parent of the hdlg in order to make CommDlg_OpenSave_GetFolderPath() work, i.e. CommDlg_OpenSave_GetFolderPath(GetParent(hdlg), ...);

PS. I think attempting to cancel the selection inside CDN_FOLDERCHANGE switch, is frankly a horrendous idea.

mitrmkar 1,056 Posting Virtuoso
tux4life commented: Thank you :P +0
mitrmkar 1,056 Posting Virtuoso

Great, computer shop project sounds like something interesting. Here is a fully working starting point for you ..

//
// Computer shop program (skeleton).
//
// Should compile cleanly on modern compilers.
//

#include <iostream>

int main()
{
    //
    // The program begins, let's display a friendly title ..
    //
    std::cout << "Welcome to the computer shop!" << '\n';

    // Todo: ... 
}
mitrmkar 1,056 Posting Virtuoso

You want to make sure that you are NOT trying to execute the DEBUG version of your executable on machines not having Visual Studio (2008) installed, i.e. build and use the RELEASE version on such machines.

Ancient Dragon commented: good suggestion :) +14
mitrmkar 1,056 Posting Virtuoso

I know this is solved, but a detail which should not go unnoticed, namely

// Allocate ...
b = new int[1000000];

// ... and delete
delete [] b;

//// instead of
// delete b;
mitrmkar 1,056 Posting Virtuoso

is there any way to know what actall files from the redist it needs, and is it ok and legal to just add them

I would oppose trying to distribute individual DLLs (you cannot know the exact conditions under which a particular file should/should not be installed etc...). IMO, letting Microsoft's redistributables to manage the setup would be the best way to go. Note that in the past, even MS has royally screwed up DLL updates (rendering machines unbootable).

Have you read Redistributing Visual C++ Files?

EDIT: Regarding dependencies in general, you'll probably find Dependency Walker useful.

mitrmkar 1,056 Posting Virtuoso

unresolved external symbol "public: __thiscall grid::grid(void)"

This is saying that you have no implementation of the grid class' constructor.

Rage A Lot commented: Thanks +0
mitrmkar 1,056 Posting Virtuoso

I believe this happens due to a typo; Theading vs. Threading .

triumphost commented: THANKS! +5
mitrmkar 1,056 Posting Virtuoso

I believe you are missing an ampersand there ...

...
void serialize(Archive & ar, const unsigned int version)
...
mike_2000_17 commented: well spotted! +13
Jsplinter commented: oh my goodness! That's it! Thank you! +3
mitrmkar 1,056 Posting Virtuoso

C++ FQA Lite may be what you are looking for.

Salem commented: That's an interesting read +17
mitrmkar 1,056 Posting Virtuoso

>> why this doesn't work correctly?

The input stream has the skipws format flag set, use noskipws to clear the flag.

Ancient Dragon commented: thanks +36
mitrmkar 1,056 Posting Virtuoso

... the file fails to open.

perror() is likely to be informative in this case.

mitrmkar 1,056 Posting Virtuoso

I just tried making the routine have a return value and no args and it works.
Then I tried adding in one argument and it fails, so it looks like the problem is with the arguments, not the return value.

This suggests mismatched calling conventions (C# is assuming Stdcall, whereas your export is Cdecl).

The following import probably works in your case:

[System.Runtime.InteropServices.DllImport("testsub.dll",
  CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)]
  private static extern int addit(int a, int b);
mitrmkar 1,056 Posting Virtuoso

>> That works, to a point. Things got pretty ugly, though, when I added the old ...
>> ... I only want the #define type statements to pre-process, not the #include.

Perhaps you'd like to 'guard' your #include s with #ifdef s, like so ..

// foo.cpp
#ifdef VERNON_COMPILES
#include <iostream>
#endif

int main()
  ...

Pre-processing would be:
g++ -E foo.cpp

and compiling would be:
g++ -D VERNON_COMPILES foo.cpp

mitrmkar 1,056 Posting Virtuoso

Something spotted .. what's up with line #1057

for(int j=5; j<-1; j++)

?

mitrmkar 1,056 Posting Virtuoso

>> But I am still a bit confused why did it work on old Turboc compilers.

See comp.lang.c FAQ list ยท Question 7.3b

mitrmkar 1,056 Posting Virtuoso

Hmm, I see you've marked this thread as solved, but anyhow ..

>> The prog works - but I want to be sure

This far I've gathered that your program goes like the following ..

WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
  HANDLE ghMutex = CreateMutex(
    NULL,              // default security attributes
    TRUE,              // initially owned
    "AnyName");        // named mutex

  if (GetLastError() != ERROR_ALREADY_EXISTS )
  {
    // I think this is the first instance ...

    try 
    {
      Application->Initialize();
      
      // <snip>

      Application->Run();
    }
    catch (Exception &exception)
    {
      Application->ShowException(&exception);
    }
    CloseHandle(ghMutex);

    return 0;
  }
  else
  {
    // I think this is NOT the first instance ...
    Application->Terminate();
  }
  return 0;
}

To test your program's behaviour, use the below console program, i.e. launch this program first and then begin launching new instances of the main program -- will the instance detection still work?

#include <iostream>
#include <windows.h>

int main()
{
  // Create an event (the name used here must match the name of your mutex)
  HANDLE hEvent = CreateEvent(0, FALSE, FALSE, "AnyName");
  
  if(hEvent)
  {
    std::cout   << "Event handle: " << hEvent << std::endl
                << "Now, start multiple instances of your main program ..." << std::endl
                << "Press Enter to exit.";
    std::cin.get();
    CloseHandle(hEvent);
  }
  else
  {
    std::cout << "Unable to create event, error: " << GetLastError() << std::endl;
  }
}
thelamb commented: Yupp, perfect example +3
Dingbats commented: very neat idea +1
mitrmkar 1,056 Posting Virtuoso

Your main() does not have the proper signature for taking arguments, you want to have ..

#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;

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

You might also want to check that argc is equal to (at least) 2.

SgtMe commented: Danke schon :D +2
mitrmkar 1,056 Posting Virtuoso

It (or any other tutorial) may come in handy later, if not immediately -- I tend to think this way, because you had obvious problems with basic C++ syntax.

mitrmkar 1,056 Posting Virtuoso

How about forgetting the extra array in main() (do you really need it at this point?), and instead go along the lines of ..

int main()
{
    srand(time(NULL));      // Seeds the random number generator
    Heap<int> heap;         // The Heap object
 
    while(!heap.isFull())
    {
        heap.insert(rand() % 190 + 10);
    }
    
    heap.display(); 

    while(!heap.isEmpty())
    {
        cout << heap.removeMax() << " ";
    }
    cout << endl;

    return 0;
}

>> tips to this Segmentation fault

You might use assert() as an aid in spotting out-of-bounds reads/writes. In other words, throughout your code, assert every access to the heap's array, like so

assert(index >= 0);
assert(index < mySize);
assert(parent < mySize);
assert(parent >= 0);
if (myArray[index] > myArray[parent])
mitrmkar 1,056 Posting Virtuoso

But I'm a little confused. I thought I did that with the 'SORTED ARRAY:' section ...

Yes, you did that correctly, however, I was suggesting that you might be stepping out of boundaries wrt. the heap's myArray[]

mitrmkar 1,056 Posting Virtuoso
void PLAYER::AddExperience(int amount)
{
    SetExperience(experience = amount);
}

I'd like to suggest a beginner-friendly C++ Tutorial.

mitrmkar 1,056 Posting Virtuoso

>> When I tried to put 'return maxItem;' out of the 'if' statement, the compiler is complaining about how maxItem is not defined. Is that what I'm supposed to do?

Strictly speaking: change your code so that you don't get that warning anymore.

About the boundaries, if you have an array of N elements, then you are allowed to access indices 0..N-1, inclusive, i.e.

const int ARR_SIZE = 3;
// An array, all elements initialized to zero
int array[ARR_SIZE] = {0};

for(int ii = 0; ii < ARR_SIZE; ++ii)
{
  // Do something with array[ii] here ..
}
mitrmkar 1,056 Posting Virtuoso

Pass the warning options on the commandline i.e. g++ -Wall -Wextra and first get a clean compile.

As to the surprise number, I believe you might be stepping outside array boundaries, which are 0..N-1, inclusive.

mitrmkar 1,056 Posting Virtuoso

>> undefined reference to `Wait()'

In Code::Blocks, be sure to add the Helper.cpp file ( Wait() is defined there) to your project and rebuild. Do the same with the file containing Crossroads() .

The compiler is not seeing the definitions of these two functions at the moment.

mitrmkar 1,056 Posting Virtuoso

In ReHeap() , comparison is used instead of assignment ..

if (left < mySize && myArray[left] > myArray[root])
  largest == left; // <--- Wrong

You should catch this by enabling basic warnings, i.e. compiling with e.g. -Wall -Wextra .

Also in ReHeap() , check that left and right are not negative when indexing into the myArray .

mitrmkar 1,056 Posting Virtuoso

>> and these are the erros i get when i try ot compile it:
>> main.cpp:4: error: '::main' must return 'int'

See Should I use void main() or int main()?

mitrmkar 1,056 Posting Virtuoso

Quite likely your project is configured to use precompiled headers through "stdafx.h".
In other words, you'll need to change the order of your includes, in order for the compiler to see <mysql.h>.

You could try ..

#include "stdafx.h" // First stdafx.h

#include <cstdio>
#include <windows.h>
#include <mysql.h>

int main()
{
  MYSQL *conn;
}
jonsca commented: Nice going. +5
mitrmkar 1,056 Posting Virtuoso

>> and yes i am using OpenProcess(CREATE_THREAD_ACCESS, FALSE, ProcessID);

A mere CREATE_THREAD_ACCESS is not enough, see CreateRemoteThread().

mitrmkar 1,056 Posting Virtuoso

There's a glitch at least in mergeArray() , if head is NULL , you end up doing head->next = newNode; -- I believe you know how to fix that.

xxunknown321 commented: Thnx so much +2
mitrmkar 1,056 Posting Virtuoso

>> Below is the program for swapping variables without any extra variable.

May I suggest that you view for example this thread ;)

jonsca commented: Yes, thanks for pointing that out! +5
mitrmkar 1,056 Posting Virtuoso

>> After each for each loop, posY should be incremented by 100. So all the boxes should be at the same x position but be 100 pixels(?) apart in the y position.

You missed the point .. incrementing posY has no practical effect in your code w.r.t. positioning the boxes. Try changing to following ..

// Initial values - outside the loop
int posX = 200;
int posY = 200;

for each (DataRow ^row in dataSet->Tables["Contact"]->Rows)
{
	TextBox ^txtBox = gcnew TextBox();
	txtBox->Location = Point(posX, posY);

	posY += 100;
	this->Controls->Add(txtBox);
				
	MessageBox::Show(row->default[0]->ToString());
}
mitrmkar 1,056 Posting Virtuoso

>> I'm trying to iterate backwards through a vector.

Consider using a reverse iterator, for an example, have a look at vector::rbegin().

Fbody commented: Good idea. Not something you need very often, but very useful when you do. +4
mitrmkar 1,056 Posting Virtuoso

>> How should I initiate the str_month, I thought that line #12 initiation is sufficient

strncpy() does not necessarily NULL-terminate the string -- so, you might do e.g. ..

str_month[3] = '\0';
mitrmkar 1,056 Posting Virtuoso

>> Why doesn't it accept the filename I give it?

open() only accepts a const char * , so you have to use c_str() ..

file.open(filename.c_str());

In your original post, you are calling main() recursively - it's a poor practice and also forbidden. You could instead devise a regular do/while loop, for example.

jonsca commented: Yep +5
mitrmkar 1,056 Posting Virtuoso

>> .. my head is just spinning

If the libraries seem daunting, you might check out a basic MSDN CryptoAPI example Creating an MD5 Hash from File Content.

Suzie999 commented: ace +1
mitrmkar 1,056 Posting Virtuoso

As far as I can see, Intrade is right. There are two vectors involved, of which the m_vParentPop2 vector doesn't seem to be getting content in any way, whatsoever -- neither in the code snippet nor in the attached files. I.e. it's a zero-sized vector, which is illegally accessed, hence being a real concern for the OP.

Intrade commented: Finally someone else sees it... +0
mitrmkar 1,056 Posting Virtuoso

It looks like it ought to work as such. However, you could check that;

  • You have the ON_WM_TIMER() macro in the dialog class' message map.
  • SetTimer() succeeds (returns a nonzero value).
  • UpdateData() succeeds (returns a nonzero value).
Jsplinter commented: Thank you so much! The bullet points made your answer even clearer! +1
mitrmkar 1,056 Posting Virtuoso

Person person = *p1;
This is copying the pointer address to the first 4 bytes of firstName in the newly created instance of Person, and then completely undone by line 27:

Sorry, but that is actually not so. Person person = *p1; does a struct assignment, i.e. copying sizeof(Person) bytes over to the local destination struct person - hence yielding two identical, distinct person structs.

The following tries to demonstrate this behaviour ..

#include <stdio.h>
#include <string.h>
#undef NDEBUG
#include <assert.h>

typedef struct
{
  char firstName[50];
  char lastName[50];
  int age;
} Person;

int main()
{
  /* Three person structs ... */
  Person  John    = { "John", "Doe", 99 },
          clone_1 = { "?", "?", 1 },
          clone_2 = { "?", "?", 2 };

  /* A pointer to John */
  Person * ptr    = &John;

  /* Initial output */
  printf("%s\t%s\t%d\n", John.firstName, John.lastName, John.age);
  printf("%s\t%s\t%d\n", clone_1.firstName, clone_1.lastName, clone_1.age);
  printf("%s\t%s\t%d\n", clone_2.firstName, clone_2.lastName, clone_2.age);

  /* Clone John into clone_1, a struct assignment ... */
  clone_1 = John;

  /* The two structs are identical */
  assert(memcmp(&clone_1, &John, sizeof(Person)) == 0);

  /* Clone John into clone_2 dereferencing the pointer, effectively the same as above */
  clone_2 = *ptr;

  /* The two structs are identical */
  assert(memcmp(&clone_2, &John, sizeof(Person)) == 0);

  /* Final output */
  printf("%s\t%s\t%d\n", John.firstName, John.lastName, John.age);
  printf("%s\t%s\t%d\n", clone_1.firstName, clone_1.lastName, clone_1.age);
  printf("%s\t%s\t%d\n", clone_2.firstName, clone_2.lastName, clone_2.age);

  return 0;
}

/* Output ...
John    Doe     99
?       ?       1
?       ?       2
John    Doe     99
John    Doe     99
John    Doe     99
*/
mitrmkar 1,056 Posting Virtuoso

>> I'm now off to learn how to compile to dll in C++, maybe it will hook me

Assuming you have some version of Visual Studio, you might go through MSDN's Walkthrough: Creating and Using a Dynamic Link Library. It's close to the simplest console app/dll configuration that one can have.

P.S. I think you should not underestimate the cheat team's capability/motivation to hack the protection (due to their young age) - there are lots of resources on internet to aid in just that - in other words, be sure to give this a good go ;)

Suzie999 commented: Useful information +1
mitrmkar 1,056 Posting Virtuoso

>> the compiler is about a year or 2 old.
>> Its a C++/C compiler. gcc

Most likely the code is not a compiled as C, but C++ instead. In C, you don't need to cast return value from malloc(), and moreover, you shouldn't do that.

sree_ec commented: nice link +1
mitrmkar 1,056 Posting Virtuoso

Since this is MFC, see CComboBox::AddString() GetDlgItem() returns a CWnd * , meaning that you need a typecast to CComboBox * .

For example

CComboBox * pCombo = (CComboBox *) GetDlgItem(IDC_COMBO1);
pCombo->AddString("Text");
fire_ commented: Thank you. It worked +1
mitrmkar 1,056 Posting Virtuoso

perror() might come in handy, so perhaps try

void uloz2D(char nazevsouboru[])
{
    // You don't need the NAZEVPR2 variable here

    printf("%s\n", nazevsouboru);

    FILE *soubor2 = fopen(nazevsouboru, "w");
    if(soubor2)
    {
        fprintf(soubor2,"A");
        fclose(soubor2);
    }
    else
    {
        // Failed, what's the reason?
        perror(nazevsouboru);
    }
}

Are you sure about your last argument to GetWindowText() , that is the count of characters that fit in the input buffer. In other words,

char retezec[32] = "";
     GetWindowText(GetDlgItem(hwnd, IDB_TEXTBOX1), retezec, sizeof(retezec));

or maybe

TCHAR retezec[32] = _T("");
     GetWindowText(GetDlgItem(hwnd, IDB_TEXTBOX1), retezec, sizeof(retezec)/sizeof(*retezec));
mitrmkar 1,056 Posting Virtuoso

Ok ... I'll admit, I'm lost. I used #defines to declare token strings. I'm not seeing how that will do anything?

You #define d wrong things then :)

How about us letting this thread get some rest and see if the OP returns?

VernonDozier commented: +rep for figuring out the #define. +11
mitrmkar 1,056 Posting Virtuoso

>> This very much looks like a 'trick' question of some sorts.

Good lord, I see what you mean.. If the teacher actually gave this assigment (s)he should be fired for encouraging this abomination of a code...

--- wait --- see my above post about the possible good outcomes of this problem .. let's not fire the teacher yet, right? ;)

Nick Evan commented: Hmmm.. I'm still not convinced, but I see your point :) +15
mitrmkar 1,056 Posting Virtuoso

When you write to the file, sizeof(m_data) gives sizeof(deque<double>) . Instead you need sizeof(double) .

Jsplinter commented: that fixed it! +1
mitrmkar 1,056 Posting Virtuoso

>> This compiles, but it is not working.

The loop condition is backwards (has ! ).
You are complicating the reading, to read a double at a time ..

ifstream myfileIN("data2.bin", ios_base::binary);
double dub;
// As long as sizeof(double) bytes is read ..
while(myfileIN.read(reinterpret_cast<char*>(&dub), sizeof(dub)).gcount() == sizeof(dub))
{
  dq.push_back(dub);
}

PS. If you'll be using strtod() , the buffer must be '\0'-terminated, like nbaztec noted.

mitrmkar 1,056 Posting Virtuoso

All the three lines of code below have undefined behaviour and are to be avoided

digit[curpos] = ((digit[curpos]++) % 10);

p = (p++) % 10; // doesn't work

x = (++x) % 10; // works

See comp.lang.c FAQ list ยท Question 3.8

creeps commented: Missed that one +1
mitrmkar 1,056 Posting Virtuoso

>> 'book_list' : undeclared identifier

In Main.cpp line #26, the missing variable has been commented out, so you need to remove
the comments to have the book_list declared.

...
// Declare the book list and an STL linked list variable
list <BookRecord> book_list;
...

On a side note, does your instructor consider the following a good/safe practice?

...
char option[3];

// Get some input, hoping that the input will fit into 'option' 
// without an out-of-bounds write.
cin >> option;
BobbieJean commented: mitrmkar's respnse to my post was the one that solved it! Thanks a bunch mitrmkar!!! +1