|
Goto declaration of RUNTIME_CLASS macro in afx.h and you will see something like
#define _RUNTIME_CLASS(class_name) ((CRuntimeClass*)(&class_name::class##class_name))
#ifdef _AFXDLL
#define RUNTIME_CLASS(class_name) (class_name::GetThisClass())
#else
#define RUNTIME_CLASS(class_name) _RUNTIME_CLASS(class_name)
#endif
If you have _AFXDLL defined in your project replace RUNTIME_CLASS(T) with T::GetThisClass()
Otherwise you will have a problem. The macro will expand to &T::classT which will fail, and you will need some other construct.
Edit: This might work (NOT tested)
template<class T> T* GetCell(int row,int col)
{
return ((T*)GridCellGet(col,row,0,0,T().GetRuntimeClass()));
}
|
|
|
|
|
Thank you, it works, but I think it always creates temporary object so it will be bit inefficient but maybe it won't be noticeable problem.
|
|
|
|
|
Ok. If performance is critical, you could solve this by having a class variable (static T temp) to use to avoid the constructor each time. Who knows, that construct might even win you some kind of most-akward-contruct-of-the-year award.
<edit>Ah forget about that and just cache the return value of T().GetRuntimeClass().
</edit>
It's a bit fishy that you had different behavior in debug and release. You might want to check what defines you have in release vs debug. If _AFXDLL is defined in debug it should be defined in release as well. Notice that it's implicitly defined when defining some other symbols like _AFXEXT (and what else)
home
modified on Tuesday, June 15, 2010 9:22 AM
|
|
|
|
|
hai
This started happening when I added a malloc and free. I checked in Debug it is while freeing the memory.
I tried the runtime lib settings.It was initally /MDd that time this error _CrtIsValidHeapPointer was coming.Then I tried to changed to /MTd then it in call stack shm_test.exe1_unlock_fhandle( ) was there.
chikach
|
|
|
|
|
What exactly is the error?
|
|
|
|
|
I m getting CrtIsValidHeapPointer debug assertion
|
|
|
|
|
There is a discussion of this assert here[^], but it basically means that somewhere in your code between malloc() and free() your memory pointer has been corrupted. Try stepping through your code with the debugger to see if you can spot where this is happening.
It's time for a new signature.
|
|
|
|
|
I need to learn C because I am about to develop microcontroller projects that use C. I got books about C.
I might need C++ in the future, but for totally different things.
Is it possible to use stdio.h in MS Visual C++?
How do I do so?
How do I keep command prompt applications from closing the console after they are done playing? If i want to see my "hello world" or some variable number output.
Is Keil uVision the only compiler to suit ARM microcontrollers?
Maybe I need something like Borland compiler so I can write ARM code and PC code on the same compiler?
Thank you.
|
|
|
|
|
have you tried:
#include "stdio.h"
|
|
|
|
|
yes i did
it doesn't add the header
gives out an error message before i run my hello world program
|
|
|
|
|
So what is the error message?
|
|
|
|
|
Just tells me that there are errors during compilation.
and displyas a built-in hello world example result
(when you choose that you want to build c++ console it already writes a c++ hello world program using iostream.h)
|
|
|
|
|
Those error messages are telling you what's wrong.
If you want help, you must tell us what the error messages say.
|
|
|
|
|
no
maybe i should switch to a different compiler
visual studio professional is very big
too big for my computer
|
|
|
|
|
cavemen wrote: no
maybe i should switch to a different compiler
visual studio professional is very big
too big for my computer
You know that you will still get these errors with another compiler, since these are compilation errors and they won't magically disappear if you use another compiler.
|
|
|
|
|
Given this and your other comments, maybe you should hold off on the 'microcontroller projects' until you have a better understanding of development. Otherwise, you'll just end up frustrated.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
I am not talking about microcontrollers right now. I will get to that.
Here is the question.
So I have Microsoft Visual C++ Express edition and I am struggling to create a C console application. I am not sure how I ADD a stdio.h header and a main source file to accept the C code.
I am sure it is possible, it is just that al defaults in VC++ are for
C++ and object-oriented programs I won't need for a while.
I can create a class. I can create a header file. I can't create a plain code file. I don't know what to type into the header file.
Thank you.
|
|
|
|
|
cavemen wrote: So I have Microsoft Visual C++ Express edition and I am struggling to create a C console application. I am not sure how I ADD a stdio.h header and a main source file to accept the C code.
From the File menu, click New then Project. In the New Project dialog, select Win32 Console Application. Give the project a name, and verify the Location. No need for a Solution. In the Application Wizard dialog, just accept the defaults. In the Solution Explorer pane on the left, right-click Source Files and select Add then New Item. Add a C++ file, and give it a name. That file should show up in the left pane under Source Files. Double-click it to start editing. Add something like the following to it:
#include <stdio.h>
void main( void )
{
printf("Hello World\n");
}
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Thank you.
But when I try to run the empty project it tells me that it cannot find a file path to my project "lesson1\debug\lesson1.exe" (lesson1 is my first project name)
this message pops out, nomatter where I create it, the desktop or the default vc++ folder in my documents.
|
|
|
|
|
cavemen wrote: But when I try to run the empty project it tells me that it cannot find a file path to my project...
Have you tried Googling for the error number/message?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
I did.
I had to hit "build solution" before running it.
However it doesn't want to compile the
#include <stdio.h>
void main( void )
{
printf("Hello World\n");
}
The building information in "Output" tells me that there is one error the compiler had to skip somewhere.
|
|
|
|
|
cavemen wrote: The building information in "Output" tells me that there is one error...
What error? What line?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
------ Build started: Project: Lesson1_2, Configuration: Debug Win32 ------
Compiling...
Lesson1_2.cpp
Hello world.cpp
c:\documents and settings\safeuser\my documents\visual studio 2008\projects\lesson1_2\lesson1_2\hello world.cpp(1) : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
Generating Code...
Build log was saved at "file://c:\Documents and Settings\SafeUser\My Documents\Visual Studio 2008\Projects\Lesson1_2\Lesson1_2\Debug\BuildLog.htm"
Lesson1_2 - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
|
|
|
|
|
cavemen wrote: c:\documents and settings\safeuser\my documents\visual studio 2008\projects\lesson1_2\lesson1_2\hello world.cpp(1) : fatal error C1010: unexpected end of file while looking for precompiled header.
See here.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
PROBLEM SOLVED
thank you everybody for your time
I had to start EMPTY CONSOLE project and add my C++ code file to that.
NO pricompiled headers. (I don't even know what they do)
|
|
|
|