|
A console window is not a normal window in any way, underneath they are very different at the thread and message queue level.
The old console sits on the CSRSS subsystem
Client/Server Runtime Subsystem - Wikipedia[^]
It was officially abandonded since Windows 7 and the console is nothing more than a subprocess with drawing capabilities which has now even been extended to hosting ubuntu linux console on Windows 64.
If you want to see how shutdown the message loop is you can't even use spy++ on the messages in a console window.
Anyhow you want to waste your time .. good luck.
In vino veritas
|
|
|
|
|
I just used a console application to set the hook, which will inject the dll with the callback. I'm getting a valid handle and the hook is executed in the address space of the target application. There are no messages to or from the console application. I'm not trying to spy anything on a console window. Maybe that was not clear.
I get a "CWPSTRUCT" with the right message code and I have trouble to convert the message/pointer to a string and write it to a file. All of this is done in the dll. I don't know, how to setup the debugger to stop inside the dll. It's more like a try and error at the moment and that can be frustrating. I don't see this as a waste of time, because I'm also learning.
I appreciate your time and help! Thank you!
|
|
|
|
|
<pre>I am implementing a MS Word report program (in MFC c++) which uses MS Word to produce some kind of report from my program.
A document that is produced is based on a template "mytemplate.dot" or "mytemplate.dotm" .
When creating "mytemplate" in MS Word, I insert an enhanced metafile picture (via clippboard) from my program. This enhanced metafile has a unique signature text "XYZ" (example).
"mytemplate' is stored in both "dot" and "dotm" formats. Any new file created in Word (2007,20016) based on these tempaltes opens correctly and I can see my enhanced metafile picture correctly displayed in Word and my unique "XYZ" is there.
Now I create a "mytemplated" based document in my c++ program (using msword.olb type library).
m_doc = documents.Add(& mytemplate,....)
Then I enumarete through inlineshapes to find the wdInlineShapePicture type (which for the test purpose is the only inlineshape in document). I find the inlineshape object without any problem ("myinlineshape"). I do myinlineshape.Copy() and then use the clipboard to copy the enhanced metafile picture to my c++ program:
OpenClipboard(AfxGetMainWnd()->m_hWnd);
HANDLE hclip = GetClipboardData (CF_ENHMETAFILE ); //first I check if CF_ENMETAFILE is available in the clippboard
everything is OK till now
Now when I use the "mytemplate.dot" format the enhanced metafile in my program is exactly the same as it in Word - (the size and number of segments is exactly the same).
When I use the "mytemplate.dotm" format, the metafile is changed - the size is different, number of segments is suddently quite small (like 19 vs 5000 in original). The picture shows the same contents but it is more like bitmap not a metafile.
Can anybody explain what can be wrong?</pre>
|
|
|
|
|
Is there any point to create a CStringList class member on heap (with new) if this member has a lot of elements ? Or is enough to declare it on stack ?
modified 19-Jun-19 6:12am.
|
|
|
|
|
Sorry? What are you trying to do, really? Could you please provide an example?
|
|
|
|
|
protected:
CStringList m_List1;
CStringList m_List2;
CStringList m_List3;
CStringList m_List4;
COutputWnd::COutputWnd() noexcept
{
m_List1.AddTail(_T("Item 1"));
m_List1.AddTail(_T("Item 1"));
m_List1.AddTail(_T("Item 1"));
m_List1.AddTail(_T("Item 1"));
m_List1.AddTail(_T("Item 1"));
m_List1.AddTail(_T("Item 1"));
m_List2.AddTail(_T("Item 2"));
m_List2.AddTail(_T("Item 2"));
m_List2.AddTail(_T("Item 2"));
m_List2.AddTail(_T("Item 3"));
m_List2.AddTail(_T("Item 55"));
m_List2.AddTail(_T("Item 44"));
....
}
or should I do a CSringList* m_pList1, and in c-tor I create m_pList1 = new CStringList ? That was the question.
|
|
|
|
|
There is no point (as Maximilen alrady stated) in using the heap in such a scenario.
|
|
|
|
|
no point, really.
Anyway, stop using CStringList and use a std::vector instead.
I'd rather be phishing!
|
|
|
|
|
Thank you. I would let this CStringList as it is now. I still have a question: Why should I use std::vector instead of CStringList ? Is there a plus ? Please note that my app is VC++/MFC, and CStringList is part of MFC.
|
|
|
|
|
If you are using MFC then it is fine to use its classes. However for most cases it is better to allocate most objects on the heap. Save the stack for values, pointers and very short term objects,
|
|
|
|
|
In my experience, if there is a class for your purpose to be found in STL, then it's much better to use that than a corresponding MFC class. The only exception is when you need the MFC structure to interface with a function from a third party library. (e. g. to pass it as a function argument)
The 'plus' is that
- you could port the code to any platform that does not have or use MFC
- you can use other third party libraries that don't use MFC (e. g. most third party libraries using strings in their API will use std::string, not CString)
- it's easy to find plenty of documentation and tutorials on the web, and they are all accurate, because existing behaviour of STL types never changes
- the types and functions will work very efficiently and not carry around needless ballast related to Windows stuff
- your global namespace doesn't get cluttered with symbols and macros
- you don't suffer from header dependencies, and don't need to care about order of include statements
The 'minus' is that
- for some types the STL equivalent provides less utility functions (e. g. std::string vs. CString)
- if you're already using MFC types elsewhere and don't intend to change all of them, you may need to convert data between MFC- and non-MFC types.
As for using std::vector instead of std::list, the reason is that as long as you don't delete items in the mid or at the start of the vector, it is much faster than a list.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
Stefan_Lang wrote: - you could port the code to any platform that does not have or use MFC
In my experience in non-trivial (legacy) applications that possibility does not exist unless one refactors the entire code base.
That of course precludes those cases where the application, from its inception, was written to support multiple platforms.
|
|
|
|
|
Nowadays it's not nearly as bad as it used to be. The biggest culprit was and still is the UI, and in fact any graphics or sound functionality, simply because there are no C++ standard libraries for that. However, there are OS independend libraries around for that purpose.
Everything that is in the C++ standard libraries, including STL and BOOST, should work out of the box on any OS without changing the code, unless the compiler you're using is not adhering to the standard (in which case you should consult your compilers compatibility documentation).
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
Because STL containers are much better than the MFC ones.
|
|
|
|
|
_Flaviu wrote: ... if this member has a lot of elements
Just to make a point: the elements of a container do not affect how the container itself looks like, or how it should be allocated. This is true for all STL containers, and also for CStringList.
Containers are typically designed like this: one central data structure to store the basic info about the container, and maybe it's state, and some kind of reference (or two) to the data structure(s) containing the elements. The container will take care about allocating memory for the elements on the heap. But the central structure will never need to be reallocated, nor is it very large. Therefore it is no problem at all to allocate a container on the stack.
That said, if you pass a container to a function, you should normally pass it by reference. If you don't, the container will be copied as a whole, including all the elements!
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
Thank you for your explanation !
|
|
|
|
|
Hi,
MFC app using CRecordset to transfer data to a SQL Server database.
Uses the RFX_Date mechanism mapping to SQL Server "datetime" data types, previously using the old "SQL Server" odbc driver and all was well. Trying to update to the more recent "ODBC Driver 13 for SQL Server" (TLS 1.2 support) and when attempting to write to the SQL Database I'm seeing the following exception :-
"Datetime field overflow. Fractional second precision exceeds the scale specified in the parameter binding."
Have found the following article which identifies the issue as related to the updated drivers (since SQL Server 2008) being unable to infer the precision of the parameter if not explictly detailed so throws the exception.
I tried changing the datatype on the Server to datetime2 with various precisions e.g. datetime2(0), datetime2(3) and datetime2(7), none of which worked.
I have subsequently read (here) that this issue cannot be resolved by server sides changes and is a breaking change for older clients :-<
It states there that Quote: I think the application change is just a matter of specifying a scale of 3.
I'm not sure what that means in terms of using the RFX_Date approach, will I have to write an RFX_Date2 replacement or is there one out here already?
If anyone has had a similar issue I'd appreciate hearing their suggestions on how to resolve this (preferably without having to do an update to the client app if possible).
|
|
|
|
|
Do you seriously need that precision for seconds?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Can you split the seconds field, which is currently some floating-point type, up into two integer fields, one for seconds and the other for fractions of a second?
"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
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
|
good point, should have mentioned that, it's
Quote: void AFXAPI RFX_Date(CFieldExchange* pFX, LPCTSTR szName, TIMESTAMP_STRUCT& value);
|
|
|
|
|
Well, that really does not explain what is happening. Perhaps if you showed (in your original question) the actual code and the values that cause the problem ...
|
|
|
|
|
In visual Studio, I can change the DPI Awareness in the Manifest Settings (Manifest Tool -> Input and Output )
Is it the same thing as setting it in the manifest file ?
Thanks.
I'd rather be phishing!
|
|
|
|
|
Yes, add the following lines just below the root (<assembly>) node:
<asmv3:application>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true</dpiAware>
</asmv3:windowsSettings>
</asmv3:application>
|
|
|
|
|
That's what I am doing.
Thanks.
I'd rather be phishing!
|
|
|
|