Solved

resolve following error

Posted on 2009-04-05
37
281 Views
Last Modified: 2012-05-06
wrote folloeing code, when building, gives following error..

restart.cpp(16) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
// restart.cpp : Defines the entry point for the console application.

//
 

#include "stdafx.h"

#include <windows.h>

#include <tchar.h>

#include <malloc.h>
 

#define NUM_EXE 2
 

int _tmain(int argc, _TCHAR* argv[])

{

	TCHAR *names[NUM_EXE] = {_T("c:\\path1\\abs.exe"), _T("d:\\path1\\set.exe")};

	PROCESS_INFORMATION pi[NUM_EXE];
 

	static Count = 0;
 

	memset(&pi, 0, sizeof(pi));
 

	STARTUPINFO				startUpInfo;

	memset(&startUpInfo, 0, sizeof(startUpInfo));

	startUpInfo.cb			= sizeof(startUpInfo);
 

	startUpInfo.wShowWindow = SW_SHOW;

	startUpInfo.dwFlags		= STARTF_USESHOWWINDOW;
 

	for (int i = 0; i < NUM_EXE; i++) 

	{

		int Result = CreateProcess(NULL,names[i], NULL, NULL, false, 0, NULL, NULL, &startUpInfo, pi+i);

		if(Result != 0)

		{

			Count ++;

			CloseHandle(pi[i].hThread);

		}

	}
 
 

	const int t = Count;

	HANDLE* hs = NULL;

	int handlesize = sizeof(HANDLE);

    hs = (HANDLE*)HeapAlloc(GetProcessHeap(), 0, handlesize*t);
 

	PROCESS_INFORMATION* pi1;

	int processinfoize = sizeof(PROCESS_INFORMATION);

	pi1 = (PROCESS_INFORMATION*)HeapAlloc(GetProcessHeap(), 0, processinfoize*t);
 

	TCHAR *names1[NUM_EXE];

	int ArrInfo[NUM_EXE];
 

	for (int i = 0, j =0; i < NUM_EXE; i++) 

	{

		if(pi[i].hProcess != NULL)

		{

			hs[j] = pi[i].hProcess;

			pi1[j] = pi[i];

			names1[j] = names[i];

			j++;

		}

	}
 

	do 

	{

	DWORD res = WaitForMultipleObjects(Count, hs, false, INFINITE);

	if (res >= WAIT_OBJECT_0) 

	{

		int iIndexOfFinished = res - WAIT_OBJECT_0;

		if(iIndexOfFinished != -1)

		{

			CloseHandle(pi1[iIndexOfFinished].hProcess);

			int iResult = CreateProcess(NULL, names1[iIndexOfFinished], NULL, NULL, false, 0, NULL, NULL, &startUpInfo, pi1 + iIndexOfFinished);

			hs[iIndexOfFinished] = pi1[iIndexOfFinished].hProcess;

		}

		else

		{

			break;

		}

		

	}

	} while(1);
 

	return 0;

}

Open in new window

0
Comment
Question by:Indarnav
  • 19
  • 11
  • 7
37 Comments
 
LVL 53

Accepted Solution

by:
Infinity08 earned 300 total points
Comment Utility
The error points to line 16 :

>>         static Count = 0;

and says :

>> missing type specifier - int assumed. Note: C++ does not support default-int

That's pretty clear ... You forgot to specify the type of the Count variable. Possibly int ?

        static int Count = 0;

Btw, why did you make it static ?
0
 

Author Comment

by:Indarnav
Comment Utility
tell me the best then, i can change if it does not affect the code...
0
 
LVL 53

Expert Comment

by:Infinity08
Comment Utility
I did ... in my previous code.

What's still unclear ?
0
 

Author Comment

by:Indarnav
Comment Utility
>>Btw, why did you make it static ?

i want to know what else i can make it other than static, so that it works better without affecting code?
0
 
LVL 53

Expert Comment

by:Infinity08
Comment Utility
Making it static seems pretty pointless in this case (unless I'm missing something, which is what I was asking about).

But it doesn't hurt either, so you can leave it.

Just add the "int" like I suggested.
0
 

Author Comment

by:Indarnav
Comment Utility
ok, i did and exe has built successfully. but it is not running on xp sp1, can u suggest why so? no errors.. i am double clicking but it is not starting exes defined neither start itself.
0
 
LVL 53

Expert Comment

by:Infinity08
Comment Utility
Instead of double-clicking it, try opening a command prompt (Start > Run > "cmd"), navigate to the directory that holds the executable, and call it. Something like :

        cd C:\the\directory\
        program.exe
0
 

Author Comment

by:Indarnav
Comment Utility
on built i got following warnings..

1>------ Build started: Project: restart, Configuration: Release Win32 ------
1>Compiling...
1>cl : Command line warning D9035 : option 'Wp64' has been deprecated and will be removed in a future release
1>stdafx.cpp
1>Compiling...
1>cl : Command line warning D9035 : option 'Wp64' has been deprecated and will be removed in a future release
1>restart.cpp
1>.\restart.cpp(48) : warning C4101: 'ArrInfo' : unreferenced local variable
1>Linking...
1>LIBCMT.lib(cpu_disp.obj) : warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators
1>Embedding manifest...
1>Build log was saved at "file://c:\Users\Administrator\Desktop\restart\restart\restart\Release\BuildLog.htm"
1>restart - 0 error(s), 4 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
0
 

Author Comment

by:Indarnav
Comment Utility
no running even from cmd.., when i double click processing symbol comes for a while and goes.. it seems as it starts and due to some error terminates immediately..
0
 
LVL 53

Expert Comment

by:Infinity08
Comment Utility
In cmd, you don't double-click anything ... You simply type in the name of the executable, and press ENTER.
0
 
LVL 53

Expert Comment

by:Infinity08
Comment Utility
Ok, I've got to go do something now, but I'll be back in a short while.
0
 

Author Comment

by:Indarnav
Comment Utility
i did the same way... i re tried in normal way too...
0
 
LVL 53

Expert Comment

by:Infinity08
Comment Utility
>> i did the same way...

And, did it run without error, and return you to the command prompt ?
0
 
LVL 39

Assisted Solution

by:itsmeandnobodyelse
itsmeandnobodyelse earned 200 total points
Comment Utility
>>> .CRT section exists; there may be unhandled static initializers or terminators

That means you have some managed C++ parts included which hardly could work if the rest is unmanaged (normal) C++.

Note, managed C++ or C++ .NET is actually a new language which has some syntax rules in common with normal C++. There are (rather complex) ways from one to the other but you can't simply include header files from C++ .NET in C++ without spoiling the whole project.

From your code above I couldn't see where the wrong mix-up is. Maybe in stdafx.h.

The error message tells it is in cpu_disp module. If it is code from you, you should remove any references to managed C++ there.



0
 

Author Comment

by:Indarnav
Comment Utility
Infinity08:

yes
0
 
LVL 53

Expert Comment

by:Infinity08
Comment Utility
>> Infinity08:
>>
>> yes

So, what's the problem ? Your code ran without errors. What did you expect to happen ?
0
 

Author Comment

by:Indarnav
Comment Utility
itsmeandnobodyelse:

what finally i do? code is here for ur ref.
0
 

Author Comment

by:Indarnav
Comment Utility
when i call from cmd, it did not show any error but exe has not started runing. there is no exe in task manager with that name.. neither exe called any defined exes.
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 53

Expert Comment

by:Infinity08
Comment Utility
>> it did not show any error but exe has not started runing. there is no exe in task manager with that name..

Since there was no error message, it means that it DID run - it was just over too fast for you to notice it.


>> neither exe called any defined exes.

Well, there are several things to do to debug this :

(a) do the two executables "c:\\path1\\abs.exe" and "d:\\path1\\set.exe" exist ?

(b) try adding some error management code to catch runtime errors (by checking the return codes of each function call etc.), and show a message on stderr when a problem occurs.
0
 

Author Comment

by:Indarnav
Comment Utility
ok. let me check both again
0
 

Author Comment

by:Indarnav
Comment Utility
i rechecked still same, not working on xp, on vista working fine..
0
 
LVL 53

Expert Comment

by:Infinity08
Comment Utility
What did you recheck ? What did you do ? Did you add error checking code, and additional diagnostic output ? Do the two executables I mentioned exist ?
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
Comment Utility
Did you try to run it from IDE? By clicking F5?

If yes, is the IDE on Vista or XP?

- Check the output window in XP case.

- Put a break point at any return statement if XP.

- If it breaks, check the conditions leading to the break point if XP
0
 

Author Comment

by:Indarnav
Comment Utility
what is ide? how to run form there?
0
 

Author Comment

by:Indarnav
Comment Utility
in vista i tested in normal way , by double clicking.. more strange is it is running in normal xp. but when i ran on xp sp1..it is not running..things are becoming more complicated..
0
 
LVL 53

Expert Comment

by:Infinity08
Comment Utility
>> in vista i tested in normal way , by double clicking..

Well, doing the same thing over and over won't change the behavior. Please read the suggestions we made earlier again, and try to follow them. They're needed to find out what the problem is exactly.

You're also not answering my questions for clarification, which makes it very difficult for me to help you.
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
Comment Utility
>>> what is ide? how to run form there?

IDE is the Visual Studio where you edited the sources and where you make the builds (I assume).
0
 

Author Comment

by:Indarnav
Comment Utility
oh, but my vs is installed on vista, not xp.
0
 
LVL 39

Assisted Solution

by:itsmeandnobodyelse
itsmeandnobodyelse earned 200 total points
Comment Utility
>>>> more strange is it is running in normal xp

We now have servicepack 3 on xp. What is normal xp?

Are these two different computers? Or did you add service pack 1 to a 'normal' xp and it had run before and didn't run after update?

Note, if different computers you may have different applications installed which may have installed the missing dlls in the good case.
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
Comment Utility
>>>> oh, but my vs is installed on vista, not xp.
Hmmm. Vista has much more of the newer dlls already installed than xp.

What version of the Visual Studio you were running?
0
 

Author Comment

by:Indarnav
Comment Utility
vs 2008
0
 
LVL 39

Assisted Solution

by:itsmeandnobodyelse
itsmeandnobodyelse earned 200 total points
Comment Utility
Did you copy msvcr90.dll to the target computers?

Any vs2008 (== VC9) project would need that dll cause it contains enhancements of msvcrt.dll and msvcrt20.dll which are the basic libraries for C runtime functions.

If using MFC or any third libary product you would need to copy (install) the dlls for these as well. Same applies for the .NET environment.
0
 

Author Comment

by:Indarnav
Comment Utility
i made exe with multi threaded option instead of multi threaded dll, so no need of those dlls
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
Comment Utility
>>>> i made exe with multi threaded option instead of multi threaded dll
There is not much difference (and not the difference you seem to assume). The multi threaded dll should be chosen for a dll project while the 'multi threaded' code generation is for applications. It has nothing to do which runtimes dlls were needed-

>>>> so no need of those dlls

You are wrong. The threading model only decides which C runtime dlls were used. In any case you need the VC runtime dlls which have modules for both multi-threaded and single-threaded. You may look with dependency walker (depends.exe) into your executable and surely will find a reference to msvcr90.dll.
The VC runtime dlls are msvcrt.dll, msvcrt20.dll,msvcrt40.dll and msvcrxx.dll where xx is the current version number of VC compiler - in your case msvcr90.dll. Only the last one is a matter of distribution (and change) while the others only rarely will be updated (by means of service packs not by active distribution) There are possibilities to reduce dependencies to these dlls but not for standard projects which always will need these dlls.
0
 

Author Comment

by:Indarnav
Comment Utility
i opened the exe created with multi threaded ref. image 1, the dependecies shown by dependy waler are seen clearly. please have a look of image 1. also image 2 reffering to multi threaded dll, and now compare both images.

 you can see image 2, exe is showing dependency on msvcr90.dll and also look at path from where it is running dll. (as commented by you).

so suggest me where to palce this dll in target pc? at sytem32 or same path as shown in image2.?
image-1-mt.jpg
image2--md.jpg
0
 

Author Comment

by:Indarnav
Comment Utility
i copied msvcr90.dll to system32 and made exe created with multi threaded dll, got following error...


" This application has failed to start because the application configuration is incorrect"
0
 

Author Comment

by:Indarnav
Comment Utility
i solved, thanks all.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now