|
How could I use this?
If I write
extern m_strVal;
in my main file .cpp I'd get a redefinition, wouldn't I?
Thank you!
I have no idea
|
|
|
|
|
satcat wrote:
If I write
extern m_strVal;
in my main file .cpp I'd get a redefinition, wouldn't I?
Per the documentation:
The extern keyword declares a variable or function and specifies that it has external linkage (its name is visible from files other than the one in which it's defined). When modifying a variable, extern specifies that the variable has static duration (it is allocated when the program begins and deallocated when the program ends). The variable or function may be defined in another source file, or later in the same file. In C++, when used with a string, extern specifies that the linkage conventions of another language are being used for the declarator(s).
In other words, no, you would not get a redefinition error.
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
Thank you, I'll try on this way
|
|
|
|
|
If it is a member variable of a class the extern keyword does not apply, extern applies to globaly declared (non-static) variables.
If the class variable is declared grobaly, then the extern keyword may be applied to the class variable (giving you access to all public members of that class).
If the member variable contains the same information no matter how many instances of the class are created, then you might as well make it a static member. In which case you can modify it even if no intances of the class exist yet. (Example: CMyClass::m_strVar = _T("new data");)
If you do not want to make it a public member but still want to access the member directly (without use member functions), then make the class that needs direct access a friend of the class containing them member variable.
INTP
|
|
|
|
|
I have no idea about this... Perhaps if I try to explain you with some code cuts you could help me:
In my main code1.cpp I have defined a edit box with a member variable. In my code it appears on this way:
<br />
CIVOCOMDlg::CIVOCOMDlg(CWnd* pParent )<br />
: CDialog(CIVOCOMDlg::IDD, pParent)<br />
{<br />
m_strHeard = _T("");<br />
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);<br />
}<br />
<br />
void CIVOCOMDlg::DoDataExchange(CDataExchange* pDX)<br />
{<br />
CDialog::DoDataExchange(pDX);<br />
DDX_Text(pDX, IDC_GOT, m_strHeard);<br />
}<br />
Then in this code1.cpp I create a Grammar object:
<br />
BOOL loadGrammar( TCHAR *pszFile, BOOL bDictGram,<br />
ISRGramCommon **ppISRGramCommon )<br />
{<br />
...<br />
IUnknown * pIUnkGram;<br />
CGramDictSink *pGramDictSink = new CGramDictSink(NULL);<br />
pGramDictSink->AddRef();<br />
<br />
hRes = g_pISRCentral->GrammarLoad( SRGRMFMT_DICTATION, sData,<br />
pGramDictSink, IID_ISRGramNotifySink,<br />
&pIUnkGram );<br />
<br />
pGramDictSink->Release();<br />
...<br />
hRes = pIUnkGram->QueryInterface( IID_ISRGramCommon,(void **)ppISRGramCommon );<br />
pIUnkGram->Release();<br />
<br />
hRes = (*ppISRGramCommon)->Activate( NULL, FALSE, NULL );<br />
<br />
return SUCCEEDED( hRes );<br />
}<br />
In the code2.cpp file I have:
<br />
STDMETHODIMP CGramCFGSink::PhraseFinish( DWORD dwFlags,<br />
QWORD ,<br />
QWORD ,<br />
PSRPHRASE pSRPhrase,<br />
LPUNKNOWN )<br />
{<br />
if( !( dwFlags & ISRNOTEFIN_RECOGNIZED ) ||<br />
!( dwFlags & ISRNOTEFIN_THISGRAMMAR ) )<br />
{<br />
return S_OK;<br />
}<br />
<br />
PSRWORD pSRMax = (PSRWORD)( (BYTE*)pSRPhrase + pSRPhrase->dwSize );<br />
PSRWORD pSRWord = (PSRWORD)( pSRPhrase->abWords );<br />
TCHAR szText[256] = { _T('\0') };<br />
int nWords = 0;<br />
while( pSRWord < pSRMax )<br />
{<br />
if( nWords++ != 0 )<br />
_tcscat( szText, _T(" ") );<br />
<br />
_tcscat( szText, pSRWord->szWord );<br />
pSRWord = (PSRWORD)( (BYTE *)pSRWord + pSRWord->dwSize );<br />
}<br />
<br />
SetDlgItemText(m_hDlg, IDC_GOT, "Unrecognized\0");<br />
return S_OK;<br />
}<br />
This "SetDlgItemText(m_hDlg, IDC_GOT, "Unrecognized\0");" doesn't work... It should write in the edit box the text "Unrecognized" whichever I say. I don't know what could I do so it works. Please, help me!
Thank you!
|
|
|
|
|
First:
CGramDictSink *pGramDictSink = new CGramDictSink(NULL);
// Make sure pGramDictSink is not NULL
// If it is clean up and exit with failure.
Secound:
m_strHeard does not seem to be needed, unless the string contained in it needs
to be accessed after the dialog is closed or by some other class if the dialog
is not modal.
Third:
"Unrecognized\0" is equivalent to the folowing:
char str[14] { 'U','n','r','e','c','o','g','n','i','z','e','d','\0','\0' };
You sould use "Unrecognized".
Forth:
Just incase you ever want to compile your code as UNICODE you should declare
your strings as follows:
_T("Unrecognized")
Otherwise: Using function macros like _tcscat() does not make since.
Fith:
The line "TCHAR szText[256] = { _T('\0') }" looks dangerious.
How can you be absolutly sure that the final string will not exceed the size
of the buffer. Use CString instead (if using MFC), it will dinamicaly icrease
the size of the buffer as needed.
Sixth:
As for why SetDlgItemText(m_hDlg, IDC_GOT, "Unrecognized\0") does not work.
I do not know, if the dialog handle and control ID are valid it should work.
Of cource you could be overrunning the buffer mentioned above, which may
resault in your problem (I dought it). Or if the code presented here is not part of the dialog derived class and the dialog is modal, then the function call will only occur when the dialog is closed, in which case the dialog handle will be invalid.
Seventh:
It looks like you need to add more error checking to your code.
Eighth:
In the future when you post code, use <pre> before the code and </pre> after
the code. That way the we will not have to reformat it, to see what is happening.
Finaly:
I appoligise, if I sound abrubt, but this does not seem to apply to the
originaly question at all.
INTP
|
|
|
|
|
Thank you for your help...
I'm a newbie and I have a very little bit idea about programming in Visual C++, and so I got lots of mistakes in my message. My problem is that I can't write in the main window edit box from the gramsink.cpp code. That's the reason why I wrote both codes because it's the only thing doens't work in the application.
If I write a MessageBox I get in a new window what I want to be written in the main window so the code works. If i use m_strHeard in gramsink.cpp I get theerror message "Undeclared identifier". This is what I meant with my prior question. I only wanted a method so I could write in the existing window Edit Box and not in a new window. Using extern or other way (I don't know).
Sorry if you've got disturbed with my greenness.
Regards.
|
|
|
|
|
Can anyone tell me how i can find the Hard Disk Manufacturer Serial Number (Not Volume Serial Number) ?
Any help would be greatly appreciated.
Thanks.
|
|
|
|
|
The Win32_DiskDrive class would have been my first guess, but it has no serial number property. Hmmm
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
See MS KB article Q208048.
|
|
|
|
|
Hi,
I have a question. I was given some source code which uses windows.h header. However, I need to use CCriticalSection which uses afxmt.h. Obviously, the compiler does not like it when it reaches windows.h. The original code has windows.h defined all over the place. Can I set the project setting to ignore these? Or is my only choice to remove the windows.h header. I hate changing other people's code without extreme need. Thanks.
|
|
|
|
|
The net result is to remove any extraneous inclusion of windows.h. This can be done in a variety of ways. One way would be to modify each file to include stdafx.h only. Then add all header files that do not belong to your project into stdafx.h. Even though it does not belong to your project, in this case there would be no reason to add windows.h because the AFX-related files include it automatically. Make sense?
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
Hi!
I'd like to make my status bar Right to left using the mirror technology. How can I do that??????????
|
|
|
|
|
Hi..
i work on a project that use MSSQL Server 2000 and VC++
so i would like to ask if anyone know a good site to guide
me ..
(Note : i already reading from MSDN library but i need
site that explain it in different way )
thanks)
|
|
|
|
|
Depends on what you are trying to do with SQL Server, how you want to access it (ODBC, OLE/DB, DBLib native api) and if you want to use the MFC CDatabase/CRecordset classes or do it yourself using your own class/api.
onwards and upwards...
|
|
|
|
|
Hi..
i have been doing some researches on that and i found that
ODBC and MFC classes will be good for my application.
if it help u:
the idea of my application is transferring records from
one MSSQL database to another on different server
i have to specify source and destination server
so any site is good to explain something like that
|
|
|
|
|
I am trying to automate Outlook using Visual C++. Here is what I am trying to do:
void CTestOutlookDoc::OnFileTest()
{
Outlook::CApplication pApp;
if (!pApp.CreateDispatch(_T("Outlook.Application")))
{
CString str;
str.Format("CreateDispatch() failed w/error 0x%08lx", e.m_sc);
AfxMessageBox(str, MB_SETFOREGROUND);
return;
}
pApp.m_bAutoRelease = TRUE;
pApp.Quit();
return;
}
When the code is executed, an instance of Outlook is created. However, even I call Quit() in my code, OUTLOOK.EXE still remains in Windows Task Manager after the program is quit. What should I do in order to kill the OUTLOOK process when I call Quit() in my function?
Regards,
Frank
|
|
|
|
|
Something else is awry here. Since pApp is an automatic variable, calling pApp.Quit() and returning from the onFileTest() function have the same result: pApp goes out of scope and is automatically destroyed.
I tried this same code on my machine and Outlook.exe comes and goes accordingly.
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
how can i hide Shell_NotifyIcon from other program
|
|
|
|
|
I don't quite understand your question. Shell_NotifyIcon() is a function within the Windows SDK. How/why are you wanting to hide it from some other program?
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
Agree. I want to hide Icon, created by Shell_NotifyIcon().
|
|
|
|
|
In other words, you want to know how to use Shell_NotifyIcon() .
http://www.codeproject.com/shell/StealthDialog.asp
http://www.codeproject.com/shell/ctrayiconposition.asp
http://www.codeproject.com/shell/YaTrayMin.asp
http://www.codeproject.com/shell/siv_trayicon.asp
http://www.codeproject.com/shell/trayicons.asp
http://www.codeproject.com/shell/mfcstartup.asp
http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=Shell_NotifyIcon&btnG=Google+Search
...should get you started.
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
No. I know how to use Shell_NotifyIcon().
I don't know how to use it with another's applications ( created by NOT ME )
|
|
|
|
|
So what are you wanting to do with it? Are you wanting to change the behavior of another application for which you do not have the source code?
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
I want to make something like WindowsXP hide icons.
|
|
|
|