| View previous topic :: View next topic |
| Author |
Message |
Snootae Grandmaster Cheater
Reputation: 0
Joined: 16 Dec 2006 Posts: 969 Location: --->
|
Posted: Fri Oct 03, 2008 8:46 am Post subject: C++ iostream sprintf_s |
|
|
so im no good at C++, and was just wondering, is it possible to use just one function(like sprintf or sprintf_s) without including the whole iostream
im making a dll, and including iostream makes it go from 9 kb to 450kb, for a mere 3 uses of sprintf_s
is this at all possible?
_________________
|
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Fri Oct 03, 2008 8:51 am Post subject: |
|
|
Not sure in the case of C++ but in MASM when I had to do something similar, instead of including the entire library, I just copied the code and put it as a prototype function embedded in the app and called it from that.
Not sure if you are able to get the 'source' for that function though since I don't really code C++ yet.
|
|
| Back to top |
|
 |
Snootae Grandmaster Cheater
Reputation: 0
Joined: 16 Dec 2006 Posts: 969 Location: --->
|
Posted: Fri Oct 03, 2008 8:55 am Post subject: |
|
|
i get what your saying, though i dont know how id go about get the source for it, very iffy
i can see why masm would be easier to do that sort of thing in, since you get right down to ASM, which could be done in C++, though with more difficulty
_________________
|
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Fri Oct 03, 2008 10:12 am Post subject: |
|
|
| If you're linking the runtime library statically, do it dynamically.
|
|
| Back to top |
|
 |
Snootae Grandmaster Cheater
Reputation: 0
Joined: 16 Dec 2006 Posts: 969 Location: --->
|
Posted: Fri Oct 03, 2008 10:30 am Post subject: |
|
|
well i might not even need that actually, all im trying to do is this:
| Code: | static long counter = 0
DWORD cWritten
HANDLE stdOut
CHAR outputstr[7]
stdOut = GetStdHandle(STD_OUTPUT_HANDLE)
sprintf_s(outputstr, 6, "Hello", ++counter, __LINE__)
WriteFile(stdout, outputstr, (int)strlen(outputstr), &cWritten, NULL) |
i basically just need to put text on a console i've made using AllocConsole
p.s. if you could tell me how to clear the console, that would help too
_________________
|
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Fri Oct 03, 2008 12:57 pm Post subject: |
|
|
| GetStdHandle, GetConsoleScreenBufferInfo and FillConsoleOutputCharacter.
|
|
| Back to top |
|
 |
Snootae Grandmaster Cheater
Reputation: 0
Joined: 16 Dec 2006 Posts: 969 Location: --->
|
Posted: Fri Oct 03, 2008 9:41 pm Post subject: |
|
|
SOmething like this?:
| Code: |
DWORD outputhandle;
STRING mystring;
DWORD charwritten;
INT i;
COORD spot;
mystring = "Is this going to work?"
spot.X = 5;
spot.Y = 6;
outputhandle = GetStdHandle(STD_OUTPUT_HANDLE);
for(int i=0; i<strlen(mystring);i++)
{
FillConsoleOutputCharacter(outputhandle, mystring[i], 1, spot, &charwritten)
spot.X = spot.X + 1;
}
|
i just whipped that up then, anywhere close to being right?
Edit: got it to work:
| Code: | HANDLE outputhandle;
DWORD charwritten;
INT i;
COORD spot;
char mystring [] = "Hello";
spot.X = 5;
spot.Y = 6;
outputhandle = GetStdHandle(STD_OUTPUT_HANDLE);
for(int i=0; i<strlen(mystring);i++)
{
FillConsoleOutputCharacterA(outputhandle, mystring[i], 1, spot, &charwritten);
spot.X = spot.X + 1;
} |
_________________
|
|
| Back to top |
|
 |
pkedpker Master Cheater
Reputation: 1
Joined: 11 Oct 2006 Posts: 412
|
Posted: Sat Oct 04, 2008 4:12 pm Post subject: |
|
|
exactly thats why I recommend never use C++ wrappers, C++ fucked up C is much better but it doesn't mean you can't use C++'s new command other stuff like class'es then that.. all other shit is garbage.
Plus most big companies know this.. they code most popular games in C instead of C++ take for example Quake 4 coded completely in C.
you can tell that it's a C++ wrapper then it has no [b].h file[/h] at the end
instead of #include<iostream> I would use stdio which has sprintf() what is sprintf_s() anyways some copycat of sprintf()? your just bloating your project to do the same basic shit..
like fstream file opening.. would be the same as stdio's fopen() and it would be much faster.. and the size of your file would be like 20 KB instead of 80 KB..
anyways just try to get things done without those headers with no .h at end and it will be all good.. like the string class #include <string> its so useless you could just use char* name and keep size in a int and same results.. and 50KB less in file size.
_________________
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Sat Oct 04, 2008 4:59 pm Post subject: |
|
|
| pkedpker wrote: | | Plus most big companies know this.. they code most popular games in C instead of C++ take for example Quake 4 coded completely in C. |
Uh, this is completely false.
Quake 3 was the last engine written in C. In fact, all of the engines up to Quake 3 are open source now.
Most modern engines are likely written entirely in C++/ASM for the speedy bits.
|
|
| Back to top |
|
 |
|