|
Larry Mills Sr wrote: now I must open a CStdioFile using a TCHAR filename.
Why? What's wrong with:
CStdioFile file(m_csFileName, CFile::modeRead);
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Larry Mills Sr wrote: BUT it is not a TCHAR. How do I make it into a TCHAR?
Hello Larry,
You seem to reiterate the same questions regarding TCHAR which implies that you may be confused about the subject. First thing you should know is that technically there is no such thing as a TCHAR. TCHAR simply means "Template Character" and is simply a wrapper definition for both wchar_t and char based on whether or not UNICODE is defined. In other words if UNICODE is defined then TCHAR=wchar_t otherwise its a char.
All you need to do is enable unicode support in your project and CString will default to CStringW and TCHAR will default to wchar_t. Thats all you need to do. There are some functions which may require you to convert the wchar_t to multi-byte and if you run into these types of functions you can use my previous answer to convert the wchar_t to char[^].
Best Wishes,
-David Delaune
|
|
|
|
|
More here...[^]
Larry Mills Sr wrote: m_csFileName has that filename at this point, BUT it is not a TCHAR. How do I make it into a TCHAR?
Actually the character type of the string IS the same as TCHAR.
As David mentioned, a TCHAR is just a conditional macro whose resulting type is based
on whether the _UNICODE macro is defined or not. CString is the same - its
internal string character type is determined by the same Unicode macro being defined
or not defined.
I'm still not sure where in your code you think you need this "TCHAR"...
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark,
You showed me yesturday to get a CString set for TChar you have to do so in it's constructor. Naturally all members of a class(ie, CSysData cSysData in my case) are iniatized upon insanitation therefore I would not be able to do as you did in your example using my class. So naturally I am confused and have no way of knowing what to do next, which is why I included the class header and the function(SetPath(....)) to show you and everyone else what I was doing.
This operation has to be done correctly because throughout the program I'm writing most functions will need some data from the file this class (CSysData) establishes.(ie, SystemDB.sdb).
I'm not sure what David means by setting CString to UNICODE. How, exactly? and How will that setting effect SetWindowTextW(IDC_NAME,str);(where str is CString str) or GetWindowText(str); Do you use a CString or do you have to use something else? to get the data?
A C++ programming language novice, but striving to learn
|
|
|
|
|
Larry Mills Sr wrote: are iniatized upon insanitation
Yes sometimes it happens that way.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Larry Mills Sr wrote: You showed me yesturday to get a CString set for TChar you have to do so in it's constructor.
That was yesterday, and only to specifically get the file to open,
which I thought was the problem. That was a code example which hard-coded
a valid pathname so you could check your file handling code.
This string issue is entirely separate, and I'm not sure what problem you're
having at this point Compiler errors? Runtime errors? Step through with
the debugger (it's only a handful of lines of code) and watch the value of your
strings. If they're not doing what you want, then fix the code.
Larry Mills Sr wrote: I'm not sure what David means by setting CString to UNICODE. How, exactly?
With visual studio projects, typically you just use the project/general/character set setting.
If you set this to use Unicode character set, then VS adds "/D "_UNICODE" /D "UNICODE"" to the compiler
command line. This defines two macros: _UNICODE and UNICODE. Now if you look at the header files
for CString(T) and TCHAR, you'll see that the definition of _UNICODE affects the character type
of those generic string types.
Larry Mills Sr wrote: How will that setting effect SetWindowTextW(IDC_NAME,str);(where str is CString str) or GetWindowText(str);
You use a CString and that's it. Any method that takes a CString is already coded
to take generic strings into consideration. All you have to be concerned with is passing
the appropriate type. If a method expects a CString, then pass it a CString.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote:
With visual studio projects, typically you just use the project/general/character set setting.
If you set this to use Unicode character set, then VS adds "/D "_UNICODE" /D "UNICODE"" to the compiler
command line. This defines two macros: _UNICODE and UNICODE. Now if you look at the header files
for CString(T) and TCHAR, you'll see that the definition of _UNICODE affects the character type
of those generic string types.
Please be patient; I don't want to mess anything up in the compiler. Are you saying I need to go into the compiler settings and ADD a "/D" to it's settings in order for my CStrings to work as correct filenames? for "CStdioFile". Or did I missunderstand you?
A C++ programming language novice, but striving to learn
|
|
|
|
|
Larry Mills Sr wrote: Are you saying I need to go into the compiler settings and ADD a "/D"
No. That's what the Visual Studio does for you when you change the character set setting.
I still don't know what problem(s) you're having...
Compiler errors? Linker errors? Runtime errors? Not doing what you expect it too when it runs?
Larry Mills Sr wrote: in order for my CStrings to work as correct filenames? for "CStdioFile".
You don't have to do anything.
CStdioFile::Open(), for example, takes a LPCTSTR as an argument.
Since CString has a LPCTSTR casting operator, you can use a CString anywhere a LPCTSTR
is expected:
CStdioFile file;
file.Open(SomeCString, ...
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
The error I was getting was a runtime error saying among other things "Disk Full" when I have over 65GB remaining. I checked each time and the path was exactly right. When I changed it using the CString constructor method of loading the CString(like you did) I didn't get any errors and the file was written to.
Mark, it's simply confusing. You say that you can use CString anywhere it wants a LPCTSTR (is that true only if you have the "/D" setting in the compiler? It sure doesn't work correctly if you ASSIGN another CString's data into the one you want to use for a CStdioFile filename!. That's what I'm trying to solve. You've seen my code; I've got to be able to save the filename in my class (CSysData::m_csPath and the newly created CSysData::m_IsFileName). m_IsFileName will be the file that I will hopefully find at the path represented by CSysData::m_csPath. But I can't get CStdioFile::Open(filename,....,) to accept my CString::m_csPath + CSysData::m_IsFileName combination.
I can hardcode the paths for the file but I cannot hardcode the CSysData::m_IsFileName CString, because part of the name for the CSysData::m_IsFileName will be determined later adding date and time to it to make it a unqinue(ms) filename.
A C++ programming language novice, but striving to learn
|
|
|
|
|
Larry Mills Sr wrote: You say that you can use CString anywhere it wants a LPCTSTR (is that true only if you have the "/D" setting in the compiler? It sure doesn't work correctly if you ASSIGN another CString's data into the one you want to use for a CStdioFile filename!.
Yes, you can pass a CString object anywhere a LPCTSTR is the argument type. That means you can pass
a CString to CStdioFile::Open() NO PROBLEM. This has nothing to do with compiler settings. CString
is a string of a generic character type. The 'T' in LPCTSTR indicates it is a pointer to a generic
character type string. CString has a LPCTSTR operator. That makes a CString usable in place of a LPCTSTR,
regardless of whether you're building with _UNICODE defined or not.
If it doesn't work at runtime, then the contents of your string are WRONG.
It seems you need to focus on your string building. Have you stepped through with the debugger?
It doesn't matter what logic you go through to get a pathname for a file....however you build that
pathname, it needs to be valid for the file to open. If the file is not opening then your pathname is bad!
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Larry Mills Sr wrote: now I must open a CStdioFile using a TCHAR filename
Where do you get that from? TCHAR is not mentioned anywhere in the CStdioFile/CFile docs.
CFile::Open() takes a LPCTSTR type argument for the pathname.
Larry Mills Sr wrote: m_csFileName has that filename at this point
Then all you need to do is use m_csFileName (I'm assuming m_csFileName is a CString):
CStdioFile myfile;
myfile.Open(m_csFileName, ...);
Seriously - step through this SetPath() method in the debugger. Look at the values of the
strings after each line is executed.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I have walked through SetPath and I have stepped through FileSaveys. The values are exactly the same. I don't know what's going on; I just know that it is not doing as it is supposed to. I believe everything you are telling me Mark. Believe me that the error message is telling me my path is wrong when I KNOW it is the same. Or the debugger is lying to me. It's there and it's correct!. I took the same path and created a different CString varable, placed it into that CString's constructor and there was no problems. If you woul, use my class and create a file-path by adding CStrings together and see it that works on your machine. Again I've checked SetPath, and at the very point that I transfer what str has in it, to the public CString varable m_csFileName is correct. m_csFileName shows in the debug as to have received the correct path. in SetPath. it also shows the correct path in FileSaveSys right up to the Open STATEMENT. I can hardcode this path. But what worries me is the actual filename I will be lokking for in the future may not be there. m_csIsFileName will be unique and I won't know it's name because the program created that name by adding the date and time to the end of the m_csWellName. "SystemDB.sdb" is only a practice/proveable file for testing the ability of the program to work correctly to that point. If the well name was Murphy13 and the date was Jan 12, 2008 the time the User called for the file is: 11:02am, the filename would be "Murphy13011220081102.ddb". But I won't know anything about that! That's why this part must work correctly, and I can't get my CStrings to coopporate.
A C++ programming language novice, but striving to learn
|
|
|
|
|
Hi,
I've added a toolbar in a dialog based project following
what's written in this page:
http://www.codeproject.com/KB/dialog/dialog_tips.aspx[^]
The project already has a menu bar so in the toolbar I've set
the same ID for buttons having a corresponding menu item.
Now the situation is the following:
when I push toolbar buttons the application calls automatically
the callback associated to the right menu item but...
I don't know how to let the toolbar buttons be enabled or disabled
according to menu items (ON_UPDATE_COMMAND_UI).
How can I solve this problem?
Thanks a lot.
|
|
|
|
|
|
Currently, I am working on a GUI for video surveillance-object detection using MFC and is rather unfamiliar in using the MFC. I wonder if anyone here would able to give me some advice for source code for the following:
1) Using a dialog-based application in C++6.0, how do I capture live video from the webcam to the dialog box itself (i.e. picture control) using OpenCv (without using directshow)? I should be able to click on buttons created and the livevideo will start/pause/stop on the dialog box(i.e. picture control).
For now, I am thinking of this method whereby I follow the below link to create the picture control and let it draw the bmp file.
http://www.codeguru.com/cpp/g-m/bit...icle.php/c4939/
This implies that I need to convert the opencv's ipl file to mfc's bmp file and deal with multiple images so as to provide realtime images. Thinking of using a 'for' loop to perform the capturing of multiple images, but would like to ask if you have any better suggestions?
2)As I will need to store the bmp files to be processed for object recognition when I press the "InitializeDetector" button created, I would like to ask if anyone knows how to create a framegrabber? How do I store the files for image processing?
Please advise.
Thanks in advance!
|
|
|
|
|
|
I have this existing MFC application. I'd like some external C#/Silverlight application to communicate with it. Does anyone know how to add code so it can act as web service? Any pointer to articles / sample is welcome!
Thanks in advance!
|
|
|
|
|
|
ohhh you are being harsh ... I know roughly a web service is. But true not that much. I know it's stateless and that you can pass it some SOAP command...
What I want to do is provide an API to my MFC application... some way of communicating between a web app and my app... A web service seemed a good idea - do say if I am wrong!
|
|
|
|
|
BadJerry wrote: do say if I am wrong!
I can't say and wasn't saying a Web Service is the wrong solution.
BadJerry wrote: ohhh you are being harsh
I'm not being harsh, the reality of what it takes to have a Web Service might be harsh but I didn't invent them.
BadJerry wrote: I know roughly a web service is. But true not that much.
Well then I guess you better get to reading eh? That Wiki page has a bunch of links at the bottom. Should keep you busy for quite a while. Good luck
led mike
|
|
|
|
|
Hi, Jerry.
You're looking at a multi part solution. First, create a new C# Web Service project in Visual Studio. If you're comfortable with C#, writing the web service code is pretty straightforward. Just be sure to keep the member functions public and use the [WebMethod] tag for the routines you want to make publicly available via the service.
After you've created your web service, go to your C++ app and in the Solution Explorer of Visual Studio, add a Web Reference pointing to your web service (you'll get a dialog prompting you for services in this project, on local host, or a remote url).
This web reference creates a C++ proxy class header file. You can then use this class in your C++ app to talk to the web service API. You'll need to use BSTRs instead of CStrings, etc., but by looking at the proxy header file the params will be obvious to you.
I don't have any ready articles to point you to, but if you search for them on each of the steps I've mentioned, you should find plenty of starter code to get you going.
Hope this helps,
|
|
|
|
|
Hi Christopher,
Thanks for your input. Yes I have managed to create a Web Service in C# in the past and it is straightforward. But what I want to do is the other way round. I would like a C# application or silverlight or whatever to communicate with my MFC application (a big mother who acts a bit like a service). I want to provide an API to this MFC app in other words. In the past, I would have used a COM object but I'd like something more future proof - hence a web service.
The web service would have methods to check the state of the MFC app or to request the app to do something.
That's it... and I am wondering about which architecture I should go for.
Any advise welcome!
Jerry
|
|
|
|
|
I'm not sure that a web service is really a relevant solution for what you're looking to do. Sounds more like you're looking for an appropriate choice for inter process communications.
Since the MFC app is doing all the heaving lifting and you have .NET apps that you want to talk to it, COM is actually a reasonable solution (I can't believe I just called COM reasonable). Alternatively, you could set up communication through sockets or named pipes (haven't tried accessing shared memory yet in the .NET world.
Trying to force this into a web service architecture just because it's the current trendy thing is rarely a good idea froma technical point of view. Of course, resume enhancement is another matter entirely.
|
|
|
|
|
Not too much thinking of my resume but yes, I am trying to get out of my comfort zone... and I'd like the app to have a zingy Silverlight front end
And if it's a web service it means it's easier to document and for other programmers to be involved rather than named pipes or sockets... a bit more OO...
Thanks again for your advices!
|
|
|
|
|
Well, if you have your heart set on a web service, then probably the best approach is to expose functionality in the MFC app via COM and have the web service act as an intermediary, making COM calls to MFC and passing the results back to the caller of the web service. I don't see any reason why that shouldn't work for you.
Have fun!
|
|
|
|