|
this gets LNK2001: unresolved external
9ine
|
|
|
|
|
Try this[^].
Maxwell Chen
|
|
|
|
|
|
Your code must be in the header file. You can either put it after the class definition and use the keyword inline or put the code inside the class definition right where you declare the method. In both cases, don't use the inline keyword inside the class definition.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Well its a wierd to put function defenition into the header file, the only situation for this when you have templates
In Borland Builder we can keep inline function defenition in cpp files.
Can we keep somehow in VC++ inline functions declared in cpp file?
but anyway it is now compiled
"test.h"
class test
{
...
inline void function();
}
inline void test::function()
{
...
...
}
9ine
|
|
|
|
|
You can put inline function definitions in the .cpp file, but the compiler will never inline them. If you want the compiler to inline them, they must be in the header file. I'd be surprised if Borland does this differently.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
I dont know if Borland really makes them inline but it doesnt produce error link messages when inline function is in cpp file compared to VC++
9ine
|
|
|
|
|
I once tested with VC++ 6.0 many years ago. The EXE size of inlined build was fatter than non-inlined.
[Edited] Worth to mention by the way, well-designing the code is much more important than the inlining toy regarding to the performance. [/Edited]
Maxwell Chen
-- modified at 13:53 Sunday 16th April, 2006
|
|
|
|
|
code size does not depend I presume on the inline or not. Executable size comes in quanta as in quantum physics, and it does not compile it larger until some amount of code is added, that is some reservation of space and if the code exceeds it then there comes increase in exe file and another reservation. it is just happenstance to get it grow larger introducing inline funcs.
9ine
|
|
|
|
|
9ine wrote: code size does not depend I presume on the inline or not. Executable size comes in quanta as in quantum physics, and it does not compile it larger until some amount of code is added, that is some reservation of space and if the code exceeds it then there comes increase in exe file and another reservation. it is just happenstance to get it grow larger introducing inline funcs.
This is the general case when we are developing our code.
In the beginnig, the output exe is 16KB.
We add some code, and it keeps in 16KB for a while.
And suddenly it becomes 20KB ... and then 24KB ...
- - -
But what I pointed out was:
- You implement some inline global or member functions, and have them heavily invoked everywhere in the code. In other words, you just mean to concentrate in playing inline topic.
And don't just implement such kind of code as:
int MyClass::GetNumber() {<br />
return _iNum;<br />
}
but do something more overhead as:
int MyClass::GetNumber() {<br />
BYTE data[5] = {0};<br />
data[1] = 1;<br />
data[2] = data[1] * 3 + 4;<br />
data[3] = data[4] & ~data[2];<br />
data[5] = (BYTE)_time(NULL);<br />
}
1) Turn OFF the inline switch in the compiler option, comment out the inline keyword, and compile it.
2) Turn ON the inline switch in the compiler option, put the inline keyword back, and compile it.
The term code bloat is seen in each articles and books talking about inline functions.
For example: [9.3] Do inline funcitons improve performance?[^]
Maxwell Chen
|
|
|
|
|
Dear gurus,
I have a question concerning collisions between rectangles.
I have to test if 2 sprites collide together in standard C without Win32 API
I have built the following structures:
<br />
typedef struct _SPRITEDESC <br />
{ <br />
POINT location; <br />
DIRECTION direction; <br />
SIZE size; <br />
unsigned short* table; <br />
unsigned short* masks; <br />
} SPRITEDESC, *PSPRITEDESC; <br />
<br />
typedef struct _POINT <br />
{ <br />
int x, y; <br />
} POINT, *PPOINT; <br />
<br />
typedef struct _SIZE <br />
{ <br />
int cx, cy; <br />
} SIZE, *PSIZE; <br />
<br />
typedef enum _DIRECTION <br />
{ <br />
DIRECTION_NONE, <br />
DIRECTION_UP, <br />
DIRECTION_DOWN, <br />
DIRECTION_LEFT, <br />
DIRECTION_RIGHT, <br />
} DIRECTION<br />
and I need to write a function with a similar header:
bool SpriteCollide(SPRITEDESC s1, SPRITEDESC s2); <br />
that tells if the two sprites enter in collision or not.
How can I proceed?
Can someone help me please?
Best regards.
Fred.
There is no spoon.
|
|
|
|
|
|
Hi,
Thanks, but I wish not using Win32 API.
I said standard C with no Win32 API.
But it is the function I'm seeking for...
Where can I get the source code of this API?
Thanks.
There is no spoon.
|
|
|
|
|
|
Hi,
As you will notice I am new to this forum. I have a question that you'll consider the most trivial question ever.
I already have a fairly intermediate level in C++ but I always used the "Microsoft Visual C++ 6.0 Introductory edition" software that came with my textbook to write C++ programs. What i used to do is file->new->files->C++ source file (or C/C++ header file) and then write my program, compile it, build it and execute it. Then i always used to delete all the file that were automatically created (other than the .cpp file of course).
I now have Microsoft Visual Studio .NET 2003 but I can't understand a world of its huge "help" content. Can someone point out at some place that really explain STEP BY STEP and in DETAILS what should i do to run codes i have already written, or to write new c++ codes? what are solutions? what are projects? in the C++ projects, what are ASP.NET services, ATL project, ATL Server Project, and the many other options?
thank's guys for any reply.
|
|
|
|
|
How about buying a book or getting one from the library?!
Maxwell Chen
|
|
|
|
|
When you open VC 2005, create a new project, but instead of adding new source/header files like you have been doing, you should add your already created files to the project.
After you created the new project, in a window on the left of the screen, you can see your project files, just as you could with VC6. Right click this and choose 'add files to project', browse for your source files and add them. Once added you can compile them pretty much the same as you could in VC6.
|
|
|
|
|
I have code to run through all the running processes and it gives me the PID of the program that I need. I got OpenProcess to work fine. This is what I have for code:
<code>#include <windows.h>
#include <psapi.h>
//Maximum processes
#define PROCMAXCOUNT 4096
int main()
{
int aa,bb,mode=0;
int IsProgram; //Used to check if a process is StarCraft
DWORD pIDs[PROCMAXCOUNT],pIDssz,pIDscount,Modssz,Modscount;
HANDLE proch;
HMODULE Mods[4096];
unsigned char mbasename[MAX_PATH];
MODULEINFO minfo;
char str[13] = "Program.exe"; //Process Name
HANDLE hProcess;
PBYTE pBuffer;
DWORD dwBaseAddress = 0x0114772C;
DWORD lSize = 0;
DWORD lRead = 0;
/* enumerate processes */
if (EnumProcesses(pIDs,sizeof(pIDs),&pIDssz)==FALSE) {
printf("Error getting process list.\n");
return 1;}
/* show processes info */
pIDscount=pIDssz/sizeof(DWORD);
for (aa=0;aa<pIDscount;aa++) {
/* open process */
if (!(proch=OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ,FALSE,pIDs[aa]))) {
continue;}
/* enumerate modules */
if (!EnumProcessModules(proch,Mods,sizeof(HMODULE)*4096,&Modssz)) {
continue;}
Modscount=Modssz/sizeof(DWORD);
/* first module representes own process */
if (!mode) {
Modscount=1;}
for (bb=0;bb<Modscount;bb++) {
GetModuleBaseName(proch,Mods[bb],mbasename,MAX_PATH/sizeof(unsigned char));
IsProgram = strcmpi(str,mbasename);
if(IsStarCraft == 0) //checks if process name is StarCraft.exe
{
printf("Process ID: %i\n",pIDs[aa]);
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pIDs[aa]);
if (hProcess == NULL) { printf("Error opening process with OpenProcess()\n"); }
if (ReadProcessMemory(hProcess, (LPVOID)dwBaseAddress, pBuffer, lSize, &lRead))
{
printf("%s",pBuffer);
}
else { printf("ReadProcessMemory failed.\n"); }
}
}
}
return 0;
}</code>
ReadProcessMemory works fine if lSize is 0, but not if I set it to anything else. So, I have these questions:
1) Is dwBaseAddress being used correctly for the specific address I need?
2) How do I get ReadProcessMemory to read a string from memory and display it as ASCII?
3) What do you set lSize to if you want to read a 4-byte long integer? Setting it to 4 or 0x4 doesn't work.
Thanks in advance.
-- modified at 11:40 Saturday 15th April, 2006
|
|
|
|
|
slippnslide wrote: 1) Is dwBaseAddress being used correctly for the specific address I need?
The base address is the value of the HINSTANCE for the module you're reading from.
slippnslide wrote: 2) How do I get ReadProcessMemory to read a string from memory and display it as ASCII?
ReadProcessMemory() doesn't do any display - you use it to read the bytes you want and then do the display yourself.
slippnslide wrote: 3) What do you set lSize to if you want to read a 4-byte long integer? Setting it to 4 or 0x4 doesn't work.
Err... 4. You're reading 4 bytes, so set lSize to 4. 4 will work if you have got the address correct.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Hi everyone,
I am using a dialog application and I want to use Message Boxes to send messages to the user. However they seem to be hidden behind the dialog application. As a consequence I have to press the TAB key once and then press Enter to get back to interact with my application. I read in the Microsoft Helo that pressing the TAB key looses the focus of a control. Why does my message box not appear over my dialog application?? Is there another easy way of sending messages to the user. I don't really want to create a lot of modal dialogs.
Can anyone help me with this problem please? I would appreciate any help at all!!
|
|
|
|
|
Laughing Buddha wrote: However they seem to be hidden behind the dialog application.
Check that you're passing the right parent handle to the MessageBox() function. If you're using MFC, you may find it more convenient to use AfxMessageBox() .
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
Set the parent of the messagebox as that of your dialog .(pass the dialog's handle to the messagebox).
Regards,
FarPointer
|
|
|
|
|
AfxMessageBox("Sample topmost messagebox in MFC",MB_TOPMOST);
|
|
|
|
|
Argh. Not topmost message boxes. I hate them. What if the user wants to switch away from your application? They shouldn't be forced to close some silly message box just to use another application.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Ryan Binns wrote: They shouldn't be forced to close some silly message box just to use another application
Yeah, your probably right. We should let the important message linger somewhere behind all those other windows. I always love it when I'm trying to close my windows and a stray message box is hiding behind the others keeping me from closing my app until I figure out that there is a modal messagebox hidden somewhere.
|
|
|
|