Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Importing Source code snippets
Importing Source code snippets [message #725272] Wed, 14 September 2011 11:57 Go to next message
Ungeiist  is currently offline Ungeiist Friend
Messages: 3
Registered: September 2011
Junior Member
Hi, I'm having trouble understanding how to take code, copied from a forum, and put it into eclipse.

For example I copied this example program from a forum but now I have no idea how to compile and run it using eclipse on my own machine.

Should I create a new project and just insert this code somewhere?

#include <windows.h>

void suicide(unsigned long exitcode) {
	HMODULE hModule;
	char szModuleName[MAX_PATH];
    hModule = GetModuleHandle(0);
	GetModuleFileName(hModule, szModuleName, sizeof(szModuleName));
	if (GetVersion() & 0x80000000) {
		// windows 9x,ME
		__asm {
			lea	eax, szModuleName
			push	exitcode
			push	0
			push	eax
			push	ExitProcess
			push	hModule
			push	DeleteFile
			push	FreeLibrary
			ret
		}
	} else {
		// windows NT,2K
		CloseHandle(4);
		__asm {
			lea	eax, szModuleName
			push	exitcode
			push	0
			push	eax
			push	ExitProcess
			push	hModule
			push	DeleteFile
			push	UnmapViewOfFile
			ret
		}
	}
}

void main(int argc, char ** argv) {
	suicide(0);
}


Any help is greatly appreciated.
Sorry if this is a stupid question but I'm very new to this

Thanks Very Happy
Re: Importing Source code snippets [message #725306 is a reply to message #725272] Wed, 14 September 2011 13:16 Go to previous messageGo to next message
Russell Bateman is currently offline Russell BatemanFriend
Messages: 3798
Registered: July 2009
Location: Provo, Utah, USA
Senior Member

On 2011.09.14 5:57, Ungeiist wrote:
> Hi, I'm having trouble understanding how to take code, copied from a
> forum, and put it into eclipse.
> For example I copied this example program from a forum but now I have no
> idea how to compile and run it using eclipse on my own machine.
> Should I create a new project and just insert this code somewhere?
>
>[snip]

No, this isn't a stupid question at all. Many have probably different
solutions to this.

For my part, I usually keep a project in any workspace where I'll need
it named TryStuff. When I want to try out some solution or some quick
code snippet such as this one, I create a class ('cause I'm a Java guy
and no longer a C guy) in that project to try it. That way, I'm not
creating a whole new project each time.

There are probably more sophisticated solutions and these (as well as my
own) may vary for C/C++ development.

In your case, being a C (and Windows) guy, you might find more precise
help on the Eclipse CDT forum. (I have not personally used Eclipse for C
development.)
Re: Importing Source code snippets [message #725536 is a reply to message #725306] Thu, 15 September 2011 06:19 Go to previous message
Ungeiist  is currently offline Ungeiist Friend
Messages: 3
Registered: September 2011
Junior Member
Russell Bateman wrote on Wed, 14 September 2011 09:16
On 2011.09.14 5:57, Ungeiist wrote:
> Hi, I'm having trouble understanding how to take code, copied from a
> forum, and put it into eclipse.
> For example I copied this example program from a forum but now I have no
> idea how to compile and run it using eclipse on my own machine.
> Should I create a new project and just insert this code somewhere?
>
>[snip]

No, this isn't a stupid question at all. Many have probably different
solutions to this.

For my part, I usually keep a project in any workspace where I'll need
it named TryStuff. When I want to try out some solution or some quick
code snippet such as this one, I create a class ('cause I'm a Java guy
and no longer a C guy) in that project to try it. That way, I'm not
creating a whole new project each time.

There are probably more sophisticated solutions and these (as well as my
own) may vary for C/C++ development.

In your case, being a C (and Windows) guy, you might find more precise
help on the Eclipse CDT forum. (I have not personally used Eclipse for C
development.)


Thanks Smile
(no subject) [message #725538 is a reply to message #725306] Thu, 15 September 2011 06:19 Go to previous message
Ungeiist  is currently offline Ungeiist Friend
Messages: 3
Registered: September 2011
Junior Member
Russell Bateman wrote on Wed, 14 September 2011 09:16
> On 2011.09.14 5:57, Ungeiist wrote:
> > Hi, I'm having trouble understanding how to take code, copied from a
> > forum, and put it into eclipse.
> > For example I copied this example program from a forum but now I have no
> > idea how to compile and run it using eclipse on my own machine.
> > Should I create a new project and just insert this code somewhere?
> >
> >[snip]
>
> No, this isn't a stupid question at all. Many have probably different
> solutions to this.
>
> For my part, I usually keep a project in any workspace where I'll need
> it named TryStuff. When I want to try out some solution or some quick
> code snippet such as this one, I create a class ('cause I'm a Java guy
> and no longer a C guy) in that project to try it. That way, I'm not
> creating a whole new project each time.
>
> There are probably more sophisticated solutions and these (as well as my
> own) may vary for C/C++ development.
>
> In your case, being a C (and Windows) guy, you might find more precise
> help on the Eclipse CDT forum. (I have not personally used Eclipse for C
> development.)


Thanks :)
Previous Topic:Where should I post a JBoss question
Next Topic:running tomcat 7 with eclipse 3.7
Goto Forum:
  


Current Time: Thu Apr 18 09:28:41 GMT 2024

Powered by FUDForum. Page generated in 0.03316 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top