|
Get all the file (using CFile) and put it in a CString....then use SetWindowText(string)
If problems with the contents of the String when reading the file try to specify CFile::typeText open mode.
Russell
|
|
|
|
|
Works but ... it does not get rid of empty buffer stuff and it takes forever.
Thanks and see my other comments.
Cheers
Vaclav
|
|
|
|
|
Error checking is skipped, but the code should be usable:
<br />
CFile file;<br />
file.Open("file.txt",CFile::modeRead);<br />
int len = file.GetLength();<br />
TCHAR pData = new TCHAR[len+1];
int read = file.Read(pData,(len+1)*sizeof(TCHAR));<br />
file[read] = '\0';<br />
view_object.SetWindowText(pData);<br />
delete [] pData;<br />
|
|
|
|
|
I think this is the best and an efficient soulution. ( It does not read past the file lenght as I am doing and collecting nothing! ).
I want to try CArchive per Mark's suggestion.
I will post results when I am done.
Thanks
|
|
|
|
|
I'm wondering why you're using the CEditView class but not using any
of its built-in functionality?
The class comes with a built-in SerializeRaw() method for moving text into
and out of the window.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I plead ignorace.
CArchive here I came!
I still have doubts that it will get rid of the lefovers in the buffer.
Give me few hours to try it anyway.
|
|
|
|
|
Heh Note I didn't say it was THE solution....I was just wondering.
Often (always?) the canned MFC classes are ok in their simplicity, but they aren't sufficient
for everything. CEditView is a simple edit control so you're kind of stuck with the limitations
of an edit control - like plain text.
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Anyone know how I can implement this in code?
Trying to synchronize data samples from two different hardware devices. One device is sampling around 10pt/s and the other device is sampling at 50pt/s. These samples are displayed on a graph in realtime.
|
|
|
|
|
Can someone explain what "callback functions" are and how they are used? Or, point me to a good "callback functions for Dummies" web-site?
Thank you in advance
Pierre
|
|
|
|
|
|
|
vHi. I'm working on an MFC project in a company and we're stuck with Visual Studio 7.0 (2002/.Net) for the time being. I added an STL::map to a dll to hold some strings. The code compiles fine but falls over with an access violation whenever I try to do anything with the map (add items, call find() etc). It's like the container is corrupted somehow.
I've googled the problem and I've read a few other articles (eg. http://support.microsoft.com/kb/q168958/) and I think everything is set up correctly. Here's my code:
<br />
header of DLL:<br />
<br />
#pragma once<br />
<br />
namespace RegUtils<br />
{<br />
CString getRegCachedValue(const CString& p_strID);<br />
<br />
..<br />
<br />
}<br />
<br />
CPP of DLL:<br />
<br />
typedef std::map<CString, CString> RegKeyMap;<br />
typedef RegKeyMap::iterator RegKeyMapIter;<br />
RegKeyMap gRegKeyMap;<br />
<br />
CString RegUtils::getRegCachedValue(const CString& p_strID)<br />
{<br />
CString strValue = _T("");<br />
<br />
RegKeyMapIter iter = gRegKeyMap.find(p_strID);
if (gRegKeyMap.end() != iter) {<br />
strValue = iter->second;<br />
}<br />
<br />
return strValue;<br />
}<br />
As soon as the code gets to the find() method, it falls over. Ditto for any other operation on the map. Please help this is driving us nuts and I feel I've tried everything.
It's been suggested we switch to MFC maps as they apparently don't have this problem but that would be a LOT of work.
I'm using the 'Multi-threaded Debug DLL (/MDd)' runtime lib to build the DLL. I've read about problems associated with copying STL objects back and forth over DLL boundaries but I'm not doing that here - the map and this function is private to the DLL (it is not exported) and is used only internally. The code is being called by other DLLs (also built using /MDd).
Please help!
|
|
|
|
|
I'm not going to be able to find anything specific but I am sure I have done something like that in the past without problems. The most obvious difference is that I would have used a Singleton Pattern[^] rather than a global. Perhaps you might give that a try.
|
|
|
|
|
The problem is that we cannot read the < and > in your code (and for templates, it is quite annoying). Please, replace them by the two symbols that are above the emoticons.
Now for your problem, can you give a better description of the exception ? What is the exact error ? When you use the debugger, where does it crashes ? The more info you provide, the more chances you'll get help.
|
|
|
|
|
Cedric Moonen wrote: The problem is that we cannot read the < and > in your code
This is one of my pet hates. It seems that no matter how many people complain about it or how often they do so, it has little effect.
Steve
|
|
|
|
|
I don't know if this pertains to your problem but I tried using std::vector<char> in a DLL and had to do the following:
template class __declspec(dllexport) std::vector<char>;
before using it.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
What is the best way to transfer some data from one PC to another in a LAN.
I have a IP address and a Port Number.
I used to send/receive data using sockets, many years ago, but if using Visual Studio 2005 C++ MFC Dialog application, could I have a good suggestion as to what component to use.
I assume that the data interface structure needs to be defined and aggreed; i.e. I could do this and send a copy to the s/w developer on the other PC.
Many thanks,
Andy.
|
|
|
|
|
|
I can't say what the best way is for your application, but here's a description of some of the
methods available with Windows:
Interprocess Communications[^]
Given an IP and a port number (which combined, nicely defines a complete socket address)
I'd say sockets is a good option.
Regardless, both ends generally (always?) need to agree on the protocol.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi, it's me... again
I've now added GDI+ to an existing application, to allow the display of TIFF images (and other reasons). So the old "OleLoadPicture" and the IPicture have to be replaced.
I've a global var as a buffer for the image:
Gdiplus::Image *m_image;
I display the image with this code:
graphics.DrawImage(&m_image, x, y, size_x, size_y);
When I load a test image this way, it works (= it is displayed):
Gdiplus::Image m_image(L"testSMALL.TIF");
But of course I have to replace the old code, where the image is save out from a stream with the help of OleLoadPicture. I tried it this way:
LPSTREAM pstm = NULL;<br />
HRESULT hr = CreateStreamOnHGlobal(hGlobal, TRUE, &pstm);<br />
if (SUCCEEDED(hr) && pstm)<br />
{<br />
Gdiplus::Image m_image(pstm);<br />
}
But it won't compile this way. It says it has an error at the line where the "DrawImage" is:
error C2664: 'Gdiplus::Status Gdiplus::Graphics::DrawImage(Gdiplus::Image *,Gdiplus::REAL,Gdiplus::REAL,Gdiplus::REAL,Gdiplus::REAL)': Konvertierung des Parameters 1 von 'Gdiplus::Image **__w64 ' in 'Gdiplus::Image *' nicht möglich
-> in english: cannot convert the first parameter 'Gdiplus::Image **__w64 ' in 'Gdiplus::Image *'
And please don't bash me, I know that I don't have a clue about C++
Thx and Greets, Shi
|
|
|
|
|
See the double * in the error message? If you look at the start of it, the function expects the first parameter to be of type Image* , and you are passing it &m_image , and since m_image is already a pointer (its type is Image* ), you are passing the function the address of a pointer (a pointer-to-a-pointer).
Change the first parameter from &m_image to just m_image .
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
What happens if you run this code
graphics.DrawImage(m_image, x, y, size_x, size_y);
instead
graphics.DrawImage(&m_image, x, y, size_x, size_y);
|
|
|
|
|
then it works!
Thank you very much. All of you.
|
|
|
|
|
|
Hello,
Is there a way to open an explorer folder, for example C:\myprojects, inside a tabbed window of IE7; so I can save screen realestate? Because currently, when I type in "c:\myprojects" in address bar of from a new tab in IE7 it opens up a Explorer folder outside of IE7. Why not, doesn't explorer and ie7 use same underlying browser? if this is not possible how can I write a small C++ progie to do this for me? I know, microsoft will steal it and package it under WGA but it would be a nice convenience.
JavaME (J2ME), Java, C & C# Developer
CV: http://docs.google.com/Doc?id=dt6fqcn_51dn8gds
|
|
|
|