|
#pragma once or not you can define an array twice in two compilation units. Try this for example.
#pragma once
char g_hello[] = "Hello";
#pragma once
char g_hello[] = "Hello";
#include "a.h"
#include "b.h"
This code will result in "error C2374: 'g_hello' : redefinition; multiple initialization".
Steve
|
|
|
|
|
yes I misread this error with another error but...
|
|
|
|
|
Thats right, I have #pragma once included at the top of my header, and I am including .h file not the .cpp.
However, extern solution worked very well... But the question is that extern only is giving declaratin, not defination... is it? Then is any need to declare the arrays in the header file using extern keyword and then redefine the arrays in a cpp file where they are needed?
Please explain a little logic behind this and what role the extern keyword has to play there?
Polite Programmer
More Object Oriented then C#
|
|
|
|
|
extern tells your compiler that this symbol is defined elsewhere and not to worry about it if it can't find it in this compilation unit (object code). Basically it passes the problem to the linker.
If you have more than one definition for this symbol in separate cpp files the linker will complain that the symbol is already defined. This is what will happen if you try to define your array in more than one cpp file.
If you have no definition for this symbol in all your cpp files the linker will complain that it can't find the symbol.
In certain cases where it is desirable to have the definition in the header file, you can use __declspec(selectany) to indicate to the linker that if it finds multiple symbols, to just pick one.
|
|
|
|
|
A good concise explanation. The only thing missing is to point out that __declspec(selectany) isn't portable; but I guess that would be obvious to most as it's a __declspec .
Steve
|
|
|
|
|
hi ,
I am not able to Diable the Restore Button (Minimize, Restore,close) of a SDI Application. Even though I have Disabled the Close Button By removing it from system Menu.But when i apply the same Procedure to Restore Buitton I am not able to Do tht.
also, wht will be the Procedure to do the same in MDI Application.
Vinod C S
Integral Softech Technnolges
Kochi
|
|
|
|
|
An option is to handle the SC_RESTORE message in PreTranslateMessage (...).
Once you handle it make sure you don't call Base class handler. Return TRUE . This way you can disable the behavior of SC_RESTORE but the button remains there.
Another option is to use Brute Force (Remove the System Menu itself) :evilgrin:
Nibu thomas
Software Developer
Faqs by Michael dunn
|
|
|
|
|
Hi,
Can u give any sample codes for connecting server and client through OPC in MFC coding.
|
|
|
|
|
I am creating a console application,in which I create an instance on IE and hook an event sink to it.The main code is as follows:
CoInitializeEx(NULL, COINIT_MULTITHREADED);
IWebBrowser2* disp;
HRESULT hr;
hr=CoCreateInstance(CLSID_InternetExplorer,NULL,CLSCTX_LOCAL_SERVER,IID_IWebBrowser2,(void**)&disp);
if(SUCCEEDED(hr))
{
disp->put_Visible(TRUE);
LPSTREAM pStream = NULL;
//marshalling the broser interface
hr = CoMarshalInterThreadInterfaceInStream(IID_IWebBrowser2, disp, &pStream);
.......
HANDLE hThread = CreateThread(NULL, 0, ThreadProc1,pStream, 0, &dwThreadID);
WaitWithMessageLoop(hThread);
......
}
}
...........
disp->Navigate2(&vurl, &ve, &ve, &ve, &ve); */
CoUninitialize();
In threadprocfunction,i create an instance of teh sick and hook it to IE
CoInitialize(NULL);
........
// get proxy to interface and release IStream
HRESULT hr = CoGetInterfaceAndReleaseStream(pStream, IID_IWebBrowser2, (LPVOID*)&psIE);
HRESULT hr=CoCreateInstance(CLSID_InternetExplorer,NULL,CLSCTX_LOCAL_SERVER,IID_IWebBrowser2,(void**)&psIE);
....... //Create the listener instance
hr = CoCreateInstance(CLSID_emplaybacksink,NULL,CLSCTX_INPROC_SERVER,IID_Iemplaybacksink,(void**)&tsink);
....... {
AtlAdvise( psIE,pUnk,DIID_DWebBrowserEvents2,&m_dwCookie);
........ }
The Atladvise action causes IE to hang during navigation.It proceeds only after the application has exitted.It seems there is a deadlock when IE calls back into the event sink.How can i avoid it?
|
|
|
|
|
akhils wrote: Accessing global address book from outlook using c#
C# ? You're in the wrong forum, it is a C++ forum here. You'll get more success here[^]
|
|
|
|
|
hi,
Using CSplitterWnd i have spllited the client area in to two half, in one half there is a forview in other i have taken CView..Now what i want the sytle should be flat..
|
|
|
|
|
Hai ,
Can anyone tell how to 2 process at a time .. i want the process bar and adding items to list box at time..
if there are any sample projects ..please let me know...
Thanks in advance...
Vinay Charan.
|
|
|
|
|
Hi
Use threads......
AfxBeginThread()
For that you have write the procedure for thread....
Cheers
"Peace of mind through Technology"
|
|
|
|
|
can u please explain how to do that ...
|
|
|
|
|
Create Procedure as:
UINT MyThread(LPVOID lParam)<br />
{<br />
SetTimer()<br />
- - - <br />
<br />
return 0;<br />
}<br />
<br />
AfxBeginThread(MyThread,this,thread priority);
Cheers
"Peace of mind through Technology"
|
|
|
|
|
|
There are two approaches:
1. Use multiple threads; or
2. Copy and change between multiple tasks using one thread.
Steve
|
|
|
|
|
i want to develope one pop up blocker and want to run when my site is open.,
it should block unwanted URL popping up...
what to do.. i need sample codings in VC++ MFC or WTL
Ravi Chandran.C
|
|
|
|
|
See:
IHTMLDocument2 Interface.....
Cheers
"Peace of mind through Technology"
|
|
|
|
|
Dear c++ friends,
In VB we have,
Dim MyDouble, MyInt
MyDouble = 2345.5678 ' MyDouble is a Double.
MyInt = CInt(MyDouble) ' MyInt contains 2346.
Is there anything in c++ similar to CInt in VB?
Thanks,
Joy Anne
|
|
|
|
|
Joy Anne wrote: Dim MyDouble, MyInt
MyDouble = 2345.5678 ' MyDouble is a Double.
MyInt = CInt(MyDouble) ' MyInt contains 2346.
double myD = 2345.5678;<br />
int myI = (int)myD;
Maxwell Chen
|
|
|
|
|
This will not round. You need something like this:
double myD = 2345.5678;
int myI = static_cast<int>(myD+0.5);
Also note that I didn't use any C-style casts; they should never be used in C++ code.
Steve
|
|
|
|
|
Which part did my 1-voter not like: The add 0.5 bit or the static_cast lecture? I stand by both of them but I believe that if you're going to down vote something in the programming forums it's good to reply and explain your objection.
Steve
|
|
|
|
|
I voted 5 to balance it...
It used to happen on myself also, when someone doesn't feel like to see the truth.
That's also the reason I posted some reply titled "WTF ?!", remember?!
Maxwell Chen
|
|
|
|
|
Stephen Hewitt wrote: any C-style casts; they should never be used in C++ code.
Personally I guess that the 1-voter doesn't feel comfortable with the sentence above.
Maxwell Chen
|
|
|
|