mitrmkar 1,056 Posting Virtuoso

There's some evil inconsistency ...

In function.h, you declare:

void input(int* &pi, int& n, ifstream &fin);

whereas, in function.cpp you have:

void input(int* &pi,int& n, fstream &fin)

i.e., ifstream vs. fstream.

mitrmkar 1,056 Posting Virtuoso

How about using the LPARAM lp? (MSDN: An application-defined value to be passed to the callback function.)

mitrmkar 1,056 Posting Virtuoso

I believe your problem(s) have already been pointed out, but ..

anyone know what is this error

Microsoft has documented their compiler/linker error/warning codes, so, you can always look those up on MSDN, for example Compiler Error C2780.

mitrmkar 1,056 Posting Virtuoso

Then again, are you still trying to select a folder using GetOpenFileName() (which is intended for selecting files)?
...
Yes, because the UI is better than any other specific folder dialog, so it would be very nifty to be able to use it.

I was implying that it is highly unlikely that you'd find any kind of solution using GetOpenFileName(), strictly because it is not intended for selecting folders.

I ran the sample from the link you sent me, and it's exactly what it's doing: using the GetOpenFileName() GUI to selecte folders!

The GUI that you're seeing may be alike that of GetOpenFileName(), but the code does not invoke GetOpenFileName(), which (again) is a key point.

I'm still curious to know what I'm doing wrong with the hook function, but I will certainly use your sample instead.

You might post your exact code, maybe someone here might figure out what's wrong with it.

mitrmkar 1,056 Posting Virtuoso

Any idea what I'm doing wrong that prevents pnmh->code from having the real code event?

Not really, except maybe you are still doing some wild stuff ( like say, PostMessage (hdlg, IDCANCEL, 0, lTime); ) and suffering because of it? Or is your switch/case missing a break and you are falling through to CDN_FOLDERCHANGE?

Then again, are you still trying to select a folder using GetOpenFileName() (which is intended for selecting files)?

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

A cast like (LPWSTR)Buffer only silences your compiler but does not correct the problem. I'd suggest reading some tutorials ..

The Complete Guide to C++ Strings, Part I - Win32 Character Encodings

The Complete Guide to C++ Strings, Part II - String Wrapper Classes

mitrmkar 1,056 Posting Virtuoso

This one might be a good candidate Windows console tutorial / by Ben Ryves.

mitrmkar 1,056 Posting Virtuoso
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

Hmm ... is anyone else experiencing this?

At least Opera 11.61 / Windows 7 works perfectly well (regardless of zoom levels).

mitrmkar 1,056 Posting Virtuoso

do you have some examples?

You might try the following minimal snippet to see how it works - maybe it will suit you, maybe not.

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

using namespace std;

int main()
{
    // Queue the file c:\temp\foobar.txt for deletion upon next system start up ...
    MoveFileEx("C:\\temp\\foobar.txt", NULL, MOVEFILE_DELAY_UNTIL_REBOOT);

    // If the following displays zero - the operation succeeded, anything else
    // is an error code.
    cout << " GetLastError(): " << GetLastError() << endl;
}

As stated in the MSDN documentation, you need to have write access to a specific part of the system registry.

Oh, and please use the Reply to this Article -button when replying to a post i.e. do not use the Vote & Comment -button for that purpose. ;)

mitrmkar 1,056 Posting Virtuoso

what you mean?
is this a script or something?!!!!!:-O

It is a Windows API function. It can be used to delete files upon next system startup - which is what you basically seem to be wanting. So, possibly it may be of help to you - though this depends on what exactly your anti-virus thingy is.

Rasool Ahmed commented: do you have some examples? +0
mitrmkar 1,056 Posting Virtuoso

1>Linking...
1>XorCryt.obj : error LNK2019: unresolved external symbol __imp__CLSIDFromString@8

...it was hard to find the right include file and I am not sure that that is enough.

You still need to look up the necessary library (.lib), documentation CLSIDFromString function usually comes with a section titled Requirements explaining the required header/library files. In this case it is stated that you need to link to Ole32.lib .

mitrmkar 1,056 Posting Virtuoso

I finally found the solution is by removing it in system boot.

Are you aware of the regular MoveFileEx() function? It may provide a working solution in this case (i.e. you'll need to use the MOVEFILE_DELAY_UNTIL_REBOOT flag).

mitrmkar 1,056 Posting Virtuoso

Example in this thread

You'll probably find How do I remove an adware by enhance.com? useful.

PS. IMO, they should change "Powered by Text-Enhance" to "Cluttered by Text-Enhance".

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

This is somewhat off-topic (being about Facebook user's oversight instead of a scam), but anyhow, perhaps something to be aware of.

:| How Facebook ruined Thessa's 16th birthday party

mitrmkar 1,056 Posting Virtuoso

string lives in the std namespace, so e.g. std::string input; ought to work.

mitrmkar 1,056 Posting Virtuoso

This would put the whole code in that file(1.c) as it is to this file(2.c).

Yes, hence your 2.c will turn into ..

static int y=23;
void abc(int a){
 printf("%d\n",a);
 }
int main(){
 abc(12);
 printf("\n");
 printf("%d\n",y);
 return 0;
}

giving you a file-scope variable y perfectly accessible everywhere in 2.c but not in any other file -- does this make things any clearer?

mitrmkar 1,056 Posting Virtuoso

>> So, how is this static variable in 1.c printed here??

What happens when the preprocessor processes your #include "1.c" directive that you have in 2.c ?

mitrmkar 1,056 Posting Virtuoso

>> It compiles but it won't run.

It doesn't compile cleanly though, GCC spotted a number of things ..

\main.c:16:6: warning: no previous declaration for 'enter_params'
\main.c:40:6: warning: no previous declaration for 'mapping_addr'
\main.c: In function 'mapping_addr':
\main.c:49:6: warning: declaration of 'rep' shadows a global declaration
\main.c:6:5: warning: shadowed declaration is here
\main.c:54:2: warning: too many arguments for format
\main.c:66:3: warning: format '%d' expects type 'int', but argument 2 has type 'int *'
\main.c:66:3: warning: format '%d' expects type 'int', but argument 3 has type 'int *'
\main.c:121:3: warning: format '%d' expects type 'int', but argument 2 has type 'int *'
\main.c:121:3: warning: format '%d' expects type 'int', but argument 3 has type 'int *'
\main.c: At top level:
\main.c:135:6: warning: no previous declaration for 'print_pt'
\main.c: In function 'print_pt':
\main.c:145:3: warning: format '%d' expects type 'int', but argument 2 has type 'int *'
\main.c:145:3: warning: format '%d' expects type 'int', but argument 3 has type 'int *'
\main.c: At top level:
\main.c:150:6: warning: no previous declaration for 'quit_prog'
\main.c: In function 'main':
\main.c:184:1: warning: control reaches end of non-void function
\main.c: In function 'mapping_addr':
\main.c:63:7: warning: 'i' is used uninitialized in this function
\main.c:64:13: warning: 'pf' may be used uninitialized in this function
\main.c:123:5: warning: 'rep' may be used uninitialized in this function
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

...Here is the code causing the app crash:

string ReadLine()
{
	getline(file, lineread);
	if (lineread.find_first_of("WSF_") != string::npos)
	{
		return lineread;
	}
}

The function is basically badly broken -- what will it 'return' if lineread.find_first_of("WSF_") == string::npos ?

Aren't you getting any compiler warnings?

mitrmkar 1,056 Posting Virtuoso

>> Thread ID of the window (what im currently looking to get

So, if you want to know the window's thread identifier then you could give this a try

#include <windows.h>
#include <tchar.h>

int main()
{
  HWND hW = FindWindow(_T("MSBLWindowClass"), _T("Windows Live Messenger"));

  if(hW != NULL)
  {
    // Process identifier.
    DWORD PID;
    // Thread identifier.
    DWORD TID = GetWindowThreadProcessId(hW, &PID);

    // ... use PID/TID here ... 

  }
}
mitrmkar 1,056 Posting Virtuoso

Note that i is incremented at line 10

m=b[i++];
mitrmkar 1,056 Posting Virtuoso

I believe you are looking for GetWindowThreadProcessId()

mitrmkar 1,056 Posting Virtuoso

Basically, the compiler ends up seeing e.g. triangle_main.cpp (roughly) as follows

class Triangle
{
public:
  Triangle( double, double, double ) ; //constructor initializing the 3 triangle dimensions
  void calculateDimensions( double, double, double ) ; //assigns dimensions
  //int getTriangle( ) ; //get the value of the dimensions  
  void printDimensions( double, double, double ) ; //print dimensions
private:
  double side1 ;
  double side2 ;
  double hypotenuse ;

} int main( ) // <--- apparently, this will not work
{
  Triangle rightTriangle( 1.0 , 1.0 , 1.0 ) ; //create Triangle object
  return 0 ;
}
mitrmkar 1,056 Posting Virtuoso

z:\in common folder 24_09\programming\exercises deitel and deitel\ex 5.20 p242\triangle_main.cpp(7) : error C2628: 'Triangle' followed by 'int' is illegal (did you forget a ';'?)

Your compiler is making an 'educated guess' -- you need to terminate the class Triangle definition with a semicolon.

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

>> There has been an improvement. It runs a few seconds faster ...

Console output is slow, you might simply delete the line

cout << "a " << a << " b " << b << endl;

altogether.

mitrmkar 1,056 Posting Virtuoso

For a very short description of a dialog box procedure, see Dialogs. Especially your usage of DefWindowProc() in a dialog box procedure is a big no-no.

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

>> But what sort of error could be returned from either GetLastError() or ERROR_ALREADY_EXISTS for a program that hasn't even started running!?

Surely the program is running since we are talking about the return value of GetLastError() . (I don't quite get what you are saying there, sorry)

But, looking at the MSDN documentation, in case the named mutex has already been created;

If the mutex is a named mutex and the object existed before this function call, the return value is a handle (i.e. NOT NULL) to the existing object, GetLastError returns ERROR_ALREADY_EXISTS, bInitialOwner is ignored, and the calling thread is not granted ownership.

That should tell you what to check and how to interprete what GetLastError() returns.

mitrmkar 1,056 Posting Virtuoso

>> Many thanks as well

I'm not sure how to interprete this, but just note that your change:

>> I simply changed Line9 to:
>> if (GetLastError() != ERROR_ALREADY_EXISTS)

is not adequate. You really need to check what CreateMutex() returns along with what GetLastError() tells you.

[EDIT]
More discussion about the topic Avoiding Multiple Instances of an Application

mitrmkar 1,056 Posting Virtuoso

Would the OS or the compiler make a difference?

Your attempt is just a tad bit off, basically you could try

HANDLE H = CreateMutex(0, TRUE, _T("your_mutex_name_here"));

if(H == NULL)
{
    // Strict failure, GetLastError() will tell you more, perhaps ExitProcess()        
}
else if(GetLastError() == ERROR_ALREADY_EXISTS)
{
    // Prior instance detected, exit this instance.
}
else
{
    // No prior instance detected, execute the program.
    // The mutex will be automatically destroyed once the program exits.
}
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

>> multiple definition of `Wait()'

This suggests that you have the statement #include "Helper.cpp" in one or more files -- you DON'T want to #include .CPP files.

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

Alright, your project includes only the main.cpp file, through which you try to include another source file -- that is wrong. Generally, only include .h files in .cpp files.

Basically you want to add your source and header files to your Code::Blocks project so that they are visible in the Manager View. Then, when you build the project, the source files will get compiled (without being included anywhere). When setting up the project, try to do it in manageable steps (read: your code compiles), instead of adding everything at once and having maybe a hundred errors or so.

As to the semicolon-problem you are having, I cannot reproduce it (compiling your project as-is) - the only error was about undefined reference to Crossroads() , which is correct.

mitrmkar 1,056 Posting Virtuoso

>> ok i did and here is wht happens

Duh, something is amiss here, you might as well zip the project (*.h, *cpp) and post it as an attachment.

mitrmkar 1,056 Posting Virtuoso

Aha .. as a matter of the fact, you absolutely have to put that semicolon there i.e.

#include "Library.h"

//HELPER FUNCTIONS

void Wait()
{
    cout << "Press ENTER to continue\n" ; // <--- semicolon required by C++

    cin.ignore(1);
}

Now, be sure to use the above helper.cpp and rebuild -- what happens?

mitrmkar 1,056 Posting Virtuoso

Hmm, this is going round in circles, I'm having hard time in believing that the semicolon is there properly placed (see the above post) -- could you post the helper.cpp file again?