|
Nitron wrote:
OK, STL zealots, enlighten me!
Here I am, although this is not STL, it is iostream.
out << scientific << my_number << endl;
Nitron wrote:
Oh how I miss CString::Format("%.17E", MyNumber)
MFC
|
|
|
|
|
How do I set the precision? I need it to be 17.
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
Sorry, forgot about that .
cout << scientific << setprecision(17) << 0.015625f << endl;
Be sure to include <iomanip>
|
|
|
|
|
OK. works like a charm. Now 1 last issue:
I get:
x.xxxxE-002
---
|- 3 digits
instead of:
x.xxxxE-02
--
|- 2 digits
personally I wouldn't care, but the legacy lame-a$$ app that I'm supporting appearently does
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
hello,
i created a simple atl coclass with a few _bstr_t members. now i try to
initialize the variables. like m_szName = "1".
if i do so in the constructor it does not work, i have five _bstr_t variables,
and assign strings from "1" to "5", but then one variable has the value of another,
i have one missing and one twice, then it get an error if the strings are released,
and, of course, the wrong value is stored.
but if i use the same initializing in the finalconstruct method, it works.
why is that? what can be initialized in the constructor? when should i use
the finalconstruct? are there any other problems with the _bstr_t, where i cannot
use it? except for the ConvertStringToBSTR bug, i read this, but i do not know, if
it is related to my problem?
if someone knows anything, would be very helpful
thanks
enrico
|
|
|
|
|
well, i just compiled the project again, and now it is not working in the finalconstruct either.
i have following variables:
_bstr_t m_szName;
_bstr_t m_szType;
_bstr_t m_szBatch;
_bstr_t m_szPath;
_bstr_t m_szPathExact;
then i call:
m_szName = "1";
m_szType = "2";
m_szBatch = "3";
m_szPath = "4";
m_szPathExact = "5";
and the result is, that the m_szName has the same value as the m_szBatch, the m_wstr value is exactly the same, but the refcount was not incremented.
i debugged the initializing, and found that the third _com_util::ConvertStringToBSTR(s); returns the exact same pointer as the first one. and if i initialize with m_szName = L"1", i get the same result, both ::SysAllocString(s) functions return the same value.
how can that be?
thanks for help
enrico
|
|
|
|
|
Don't know, on my machine it seems to work correctly. It would probably need deeper insight. If your project is only a simple ATL object, just as was created with wizard (is here someone doing that manually?) with added _bstr_t members, it is really weird stuff.
Anyway for your first part questions, difference between constructor and FinalConstruct is in the virtual method calling - inside c-tor the vtable may not be fully constructed, so the call of a virtual method from c-tor can result in a crash. This is because in ATL your class is not the last one in a chain. (in fact your object is a CComObject<CYourClass> type)
For that reason the FinalConstruct was introduced, because it is called after the whole class hieararchy is created.
But for 'simple' initialization of your members it should make nearly no difference (ommiting the fact that from FinalConstruct you can return an error value).
|
|
|
|
|
hello,
thanks for the info with the finalconstruct.
and for the _bstr_t problem i found some more info. in fact it is working in a simple atl coclass, but i have the problem in a rather complex application. but it seems like i found an error, but i do not know, why it is like this.
i have a function
HRESULT GetSection([in] BSTR bstrSection, [out,retval] IVConfigFileSection** pVal );
it should return the section of a config file based on the section name. an empty section name should return the default section selected before.
i call this function from inside the same class like following:
CComPtr< IVConfigFileSection > pSection = NULL;
GetSection( L"", &pSection );
or
GetSection( L"MySection", &pSection );
then i get the error with the string assignment in a complete different function.
if i change the call of the function to:
GetSection( (_bstr_t)"", &pSection );
or
GetSection( (_bstr_t)"MySection", &pSection );
it works, the string assignment is correct.
so i thought maybe it has something to do with the GetSection function.
this one is very simple:
STDMETHODIMP VConfigFile::GetSection(/*[in]*/ BSTR bstrSection, /*[out,retval]*/ IVConfigFileSection** pVal )
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
*pVal = NULL;
if ( SysStringLen( bstrSection ) == 0 )
return default;
else
return other;
return S_OK;
}
now i'm not sure if it has something to do with the SysStringLen function?
or is it wrong to pass a L"Text" parameter to a function expecting a BSTR paramter?
thanks in advance
enrico
|
|
|
|
|
just now have a short time, so cannot study your sample deeper. But the fact is, that generally it is wrong to pass L"Text" parameter when function expects BSTR .
In fact it depends how the function handles the parameter and in some cases it can work, but it is not good technique.
Consider the fact, that L"Text" provides only WCHAR - this means zero terminated string. But BSTR have before the string 4 bytes containing the length of the string. Then if the function relies on these 4 bytes and you do not provide them - it will just use some garbagge 4 bytes before the string and use it as a length - what will be the result noone can say.
Hope this helps.
|
|
|
|
|
I like implement COM classes in my WTL GUI app. These COM components can be called by scripting clients to change the user interface. If I try to add a new ATL object to my WTL project, I get an error message that this is not an ATL project. When I add some ATL headers and a BEGIN_OBJECT_MAP() END_OBJECT_MAP() pair to my main file, the wizard works fine. After selecting a simple object and pressing Finish, I got another message:
Sorry! An error occurred while generating the object.
What is going wrong
Thanks
|
|
|
|
|
I made a nice toolbar like this:
<br />
CToolBarCtrl ctrl;<br />
ctrl.Create(m_hWnd, NULL, NULL, ATL_SIMPLE_CMDBAR_PANE_STYLE | TBSTYLE_FLAT | TBSTYLE_TOOLTIPS, 0, ATL_IDW_TOOLBAR);<br />
ctrl.SetImageList(largeImages);<br />
<br />
TBBUTTON ToolbarButtons[12];<br />
memset(ToolbarButtons, 0, sizeof(ToolbarButtons));<br />
int n = 0;<br />
ToolbarButtons[n].iBitmap = 0;<br />
ToolbarButtons[n].idCommand = ID_FILE_SIGNIN;<br />
ToolbarButtons[n].fsState = TBSTATE_ENABLED;<br />
ToolbarButtons[n].fsStyle = TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE;<br />
...etc<br />
<br />
ctrl.SetButtonStructSize();<br />
ctrl.AddButtons(n+1, ToolbarButtons);<br />
ctrl.AutoSize();<br />
return ctrl.m_hWnd;<br />
The returned hWnd is added to the CMainFrame as a toolbar. Works perfectly. But how do i enable/disable buttons in my toolbar?
Thank you!
|
|
|
|
|
|
Add them to the UPDATE_UI_MAP. For example,
UPDATE_ELEMENT(ID_FILE_PRINT, UPDUI_TOOLBAR)
and then in the OnIdle() handler, have something like this:
UIEnable(ID_FILE_PRINT, /* your boolean condition here */);
|
|
|
|
|
I want to create a Netscape Plug-in for custom MIME type. Can I get anything in ATL for that?
Thanks in advance
Mahesh
|
|
|
|
|
For some reason I can't find/use the ATL Object Wizard. The button to use it is disabled and its not under my Insert menu. I have the folder and all the files for the Object Wizard (C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Template\ATL) but I cannot use it. Should I reinstall or is there a way to turn it on?
Thanks for any help.
|
|
|
|
|
|
Hello,
I'm trying to use DDX_CONTROL to get to the control on my dialog in an easy way. I've declared a combo box as a private member of my dialog like this:
CComboBox m_TypeCombo;
I have a DDX map like this:
BEGIN_DDX_MAP(SearchParametersDialog)
DDX_CONTROL(IDC_SEARCH_FOR_COMBO, m_TypeCombo)
END_DDX_MAP()
Now, when I compile this, I get the following error:
c:\wtl70\include\atlddx.h(489) : error C2039: 'SubclassWindow' : is not a member of 'CComboBoxT<class atl::cwindow="">'
d:\mb-tools\explorer_plugin\src\win32\searchparametersdialog.h(32) : see reference to function template instantiation 'void __thiscall WTL::CWinDataExchange<class searchparametersdialog="">::DDX_Control(unsigned int,class WTL::CComboBoxT<class
atl::cwindow=""> &,int)' being compiled
But I don't get why it does that - CComboBox does have a method SubclassWindow! What am I doing wrong? Thanks!
|
|
|
|
|
Sorry for replying to myself, but I found an answer in http://groups.yahoo.com/group/wtl/message/4566 - however, I have no idea why this works in the first place, and secondly, why doesn't this work like it is in WTL? A bug in WTL? It looks like something that is quite common...
cheers,
roel
|
|
|
|
|
You need a CWindowImpl -derived class for DDX_CONTROL to work. CComboBox is a CWindow class (just implements a wrapper around an HWND and CB_* messages). Add this class definition to your app:
class CComboBoxImpl : public CWindowImpl<CComboBoxImpl, CComboBox>
{
DECLARE_EMPTY_MSG_MAP();
};
--Mike--
THERE IS NO THERE IS NO BUT THERE IS
MAGIC PIXIE DUST BUSINESS GENIE CODE PROJECT
Homepage | RightClick-Encrypt | 1ClickPicGrabber
"Which comes first, the bug or the stress?" -- Chris Maunder
|
|
|
|
|
Thanks Michael. Do you have any idea why this is not implemented by default in WTL? I would think this is something that is used a lot - is there a reason?
|
|
|
|
|
Since I'm not the author of WTL I can't say for sure. It's more a documentation problem (there isn't any) so the solution isn't obvious at all (I myself happened to see the answer in a discussion board somewhere on CP)
--Mike--
THERE IS NO THERE IS NO BUT THERE IS
MAGIC PIXIE DUST BUSINESS GENIE CODE PROJECT
Homepage | RightClick-Encrypt | 1ClickPicGrabber
"Which comes first, the bug or the stress?" -- Chris Maunder
|
|
|
|
|
Here´s an easyer solution:
declare you global CComboBox global variable like you did, But dont put a DDX entry for it on the map, instead on your dialogs WM_INITDIALOG handler,
add this:
m_TypeCombo.Attach(GetDlgItem(IDC_MYCOMBO));
ATLASSERT(m_MyCombo.m_hWnd != NULL);
where (of course) IDC_MYCOMBO is the ID of your combo.
Note that you can do this for any control.
Hope this helps.
|
|
|
|
|
Of course, you then defeat the purpose of DDX in the first place. With DDX_CONTROL you don't have to write all those GetDlgItem/Attach calls.
--Mike--
THERE IS NO THERE IS NO BUT THERE IS
MAGIC PIXIE DUST BUSINESS GENIE CODE PROJECT
Homepage | RightClick-Encrypt | 1ClickPicGrabber
"Which comes first, the bug or the stress?" -- Chris Maunder
|
|
|
|
|
I agree, it does sort of defeat DDX, but then again, thats the beauty of WTL, you dont HAVE to used DDX! and "all those GetDlgItem/Attach calls" is actually only one at InitDialog. NE way, i do respect your opinion, but i must say that in this case i disagree with it, i find that just adding a line of code on initdialog is easyer that writting your own dervived class, writting a DDX entry for it, etc.
|
|
|
|
|
Hello,
I am new to ATL/WTL and I don't really understand why I would need these libraries. Actually I only developed my applications with MFC and some ActiveX components. I read some articles about ATL and WTL on CodeProject. In the one hand I read 5 articles about ATL and understood nothing, the writer mostly talk about pointers and vtables... What's his point ? What about saying "ATL is...". Then I read the introduction to WTL and understood that It was somekind of MFC-COM wrapper. Why would I need a MFC-COM wrapper to developer a software ? Moreover It seems that it's not an official library and I can't find any information on MSDN:
"Your search using "All words" for ""wtl""
returned 0 results."
If you have any good articles or books to advice me, that would great. I feel like I am losing something. Is "Developer's Workshop to COM and ATL 3.0" a good reference ? I don't really understand why I would need something else that MFC to develop a Windows Application.
All your help is welcome,
JM
Web: http://goa.ifrance.com
|
|
|
|