|
George_George wrote: In VC environment, both C and C++ are using the same compiler -- cl.exe?
Yes, but depending on the File Extension it uses either the 'C' or 'CPP' front end. The Backend is mostly the same for both. You can force the CPP compiler to treat a declaration as 'C' with the 'extern "C" ' directive. Decorated names are generated differently, and those end up in the obj files. The problem is the Linker. (the 'l' in cl). It is basically stupid, and does not care about C, CPP, or for that matter ALGOL, Pascal, or basic etc, and compiled languages yet to be invented. All it sees is a number of PE .obj files, and tries to do a job of linking names with addresses. It does not know (or care) that '_myfunc',in one obj file, and '??myfunc@ABUXZ0'in another obj are meant to mean the same thing.
N.B. There are ways of exporting names without decoration, by specifying the name in a DEF File. Be carefull though, the name decoration also encodes the calling convention. ( that is, How things are laidout on the stack, and how the task of cleaning up the stack is devided between the caller and the callee. If you just mix C and CPP, don't rename member functions to global, and only use __cdecl (the default), definitely NEVER __stdcall,__pascall, etc, you should be OK.
Hope this is helpfull.
regards
Bram van Kampen
|
|
|
|
|
What does your rule "don't rename member functions to global" mean? Could you show some pseudo code please?
regards,
George
|
|
|
|
|
don't rename member functions to global, and only use __cdecl (the default), definitely NEVER __stdcall,__pascall, etc, you should be OK.
Exampe:
void CMyClass::MyFunction()
The compiler generates hidden pointers to the inststance of the class you are calling from, if you compile a member function being called from a class instance. The Name Decorating Service provided by the compiler ensures that at each stage the correct function is called. In a .DEF file you can override most things. The decorationd determine if you were calling a global, or a member function. member functions have ALWAYS as first hidden param, the pointer to the class they where called from.
If you have in your class a function fputs(LPCSTR pStr, FILE* F); what's called is something like ??MyClass@@puts@ABCD(MyClass* this,LPCSTR pStr...etc.
You create a DEF file to remap ??MyClass@@puts@ABCD to puts;
It will run: puts(this,pStr); and probably crash!
This WIL need some Name translations, but can be made to work.
btw Why are c and cpp names different.
Regards,
Bram van Kampen
|
|
|
|
|
Hi,
How can I set a bitmap on a wizard, I also tried to set bitmap on each property page but it is not fit when i run the application, Some space is coming around the bitmap.
modified on Sunday, October 5, 2008 6:41 AM
|
|
|
|
|
|
No sir, actually when I set bitmap to property page it appears but not from 0,0 pixel but from like 5,5 pixel.
|
|
|
|
|
I am in problem with static variable.Please help me.
Program:
file1.h
int x = 10;
file2.cpp
#include "file1.h"
#include "stdio.h"
extern int x;
void main() {
printf("%d",x);
}
o/p: Error(Unresolved external symbol)...
As per my knlowledge is consern I know to access x I have to use extern.But it is giving error.I want to know whts there reseaon?
Compiler: vc++ 2005(8.0ver)
|
|
|
|
|
Technically "x" isn't an extern the way you've done it. You don't need the extern keyword in file2.cpp. Extern is meant to imply that the variable is defined externally to the files that are referencing it. Since you've defined x in the header and then included it it isn't defined externally.
Also you aren't using any static variables whatsoever in the example you've provided. I think you really need to find a basic C primer on the net talking about extern and static variable and read through that since you are missing some fundemental understandings. No point writing code until you clear that up.
|
|
|
|
|
Please modify the code by which I can access x declared in file1.h in file2.cpp.
Again give me one fantastic example of usages of keyword extern.Please don't give example like below...
extern int x;
fun() {
printf("%d", x);
}
int x = 80;
fun2(){
printf("%d", x);
}
|
|
|
|
|
file1.c
-------
int counter = 1;
file2.h
-------
extern int counter;
file2.c
---------
#include "file2.h"
void countToTen()
{
while (counter <= 10) {
printf("%d\n", counter++);
}
}
Notice that counter is defined in the file.c file hence to access it we need to define it as external to our file2.c file that uses it. Hope that gives you an idea about extern vars. Similar principle applies to extern functions.
You really need to read some books on the topic.
|
|
|
|
|
Thanks a lot. It'd be great if you are sending me some useful links.
|
|
|
|
|
Does anyone have instructions on how I would go about automatically adding an auto-increment build number each time the app is compiled so that it shows up in the apps titlebar?
For eg say I have an app called Browser. First time I compile my app the title would be Browser V1.0 (build 1). I compile it again and it would be Browser V1.0 (build 2) etc.
I don't want to have to manually go into the dialog editor and change it for each compile and neither do I want to have to update a variable by hand each time for compile.
Any help would be appreciated. The language is VC++ and I'm using Visual Studio 2009.
Thanks!
PS: I'd like something that doesn't require me to alter or add stuff to the registry. I want to be able to grab the project folder, copy it to another machine and have it work straight off the bat without going through registering 3rd party dll's in the registry each time I move the source code to another PC. I found http://www.codeproject.com/KB/cpp/autobuildnumber.aspx but don't like the fact I need to go through a setup procedure that goes outside of the compiler.
Also most discussions about the topic date back 6+ years. I'm hoping MS added some functionality into VS2009 to maybe make the process simpler, more native.
modified on Sunday, October 5, 2008 8:05 AM
|
|
|
|
|
What I use is the Build Date held in the PE Header. you get that by opening your exe or dll as a binary file for reading, and wade through the headers. These headers are declared in "Windows.h". I do this once in InitInstance(), and store the value in a global time_t. You can then choose in your AboutDlg to just show this as a 'Secret' number, or format it out as a Build Date and Time. Furthermore, this info is also immediately available to your install routines, and is available for all binaries, whether built by you with this in mind, or otherwise.
regards
Bram van Kampen
|
|
|
|
|
Thanks though I would prefer something a bit easier though. Interesting idea though. I might just write a little app that increments a build number in a .h file and call that per compile. Then include that in the app for use. Shouldn't be too hard. I'm amazed MS after all these years hasn't provided what is a fundemental tool for any developer releasing images for testing.
|
|
|
|
|
montiee wrote: I'm amazed MS after all these years hasn't provided what is a fundemental tool for any developer releasing images for testing.
So am I, but well, my voting shares in microsoft are insufficient to force the issue.
montiee wrote: I would prefer something a bit easier though. Interesting idea though. I might just write a little app that increments a build number in a .h file and call that per compile. Then include that in the app for use
Well, thought of that, even wrote it. Would not use a .h file target for that though, try to line it in as a 'Pre Compile Step'
montiee wrote: Shouldn't be too hard.
That's what I thought. Success!
BTW it is very very easy to write a piece of code to get the link stamp of an exe.
Bram van Kampen
|
|
|
|
|
Hello everyone,
I asked question about debugging native code before -- mode details it is about optimized release mode x64 code which will use register to store variable which will block debugger from monitoring the variable value.
Today, I debugged a managed program, also in release build for the managed program, but I do not compile it with x64, and it is for "Any CPU". I met with the same issue and when see the assembly code, it has the same pattern that putting some variable in register prevents debugger to see its value.
My question is, I am not 100% confident enough (since the build is not for x64 release, but for "Any CPU" release, different build option from the native code issue before) and I want to confirm with you the same issue happens not only in native code in x64 release mode, but also in managed code in release "Any CPU" mode?
thanks in advance,
George
|
|
|
|
|
I am using MFC's CDialog derived class to do some lengthy task. I use a button to trigger the process. The problem I am having is: after I click the button, the lengthy task begins. However, after I switch to other programs, the dialog won't respond my click on it until the task is done.
Is there any way I can do to get rid of the problem.
|
|
|
|
|
It's normal: your application has only one thread, in which the Windows messages are processed (mouse click, click on button, ...). So, if in this thread you start a lenghty process, Windows messages are not processed anymore and your GUI will freeze (not able to respond to any messages, event not the WM_PAINT message).
The solution is to start this process in a separate thread and to keep the main dialog informed about the status by sending custom messages to it.
I suggest you read this excellent article[^], it's worth the time you will take to read it.
|
|
|
|
|
I had the same issue and found a simple solution. In the process/task that you are triggering from this dialog, insert the following code so it gets called periodically while that process/task progresses.
MSG msgs;
while( ::PeekMessage( &msgs, NULL, 0, 0 , PM_NOREMOVE ) )
{
if( !AfxGetThread()->PumpMessage() )
{
::PostQuitMessage(0);
break;
}
}
|
|
|
|
|
|
Hi
I have many sample files (of opencv) and I try to modify them so that I can get used to it. But the sample has only .c file and I need to build .cpp file to run it but I do not know how to build the .cpp file from the .c file.
Please help me.
Thank you
|
|
|
|
|
Why do you want to transform a C source file into a C++ one?
Anyway, if you simply change the file extension (to cpp ), the Visual Studio C/C++ compiler is able to differentiate.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
|
You're welcome.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Use of Visual studio 2008.
|
|
|
|
|