|
this sounds like making a string class... why not use what's there already at this point?
|
|
|
|
|
I hoped someone would get a hint!!
Watched code never compiles.
|
|
|
|
|
in that case........
|
|
|
|
|
I agree that this requirement is weird, specificallly as you are using cin and cout, which are also part of the STL, and internally do use dynamic container classes! Not to mention that for the purpose of writing and reading simple char arrays, cin and cout are hopelessly inefficient, you'd be better served with puts() and _getch() .
Since you don't know the length of the input in advance, the only way to ensure you have a sufficiently large buffer is using a container that dynamically resizes itself. If you don't want to use std::string, or other string classes like CString, then I suppose using std::vector is out of the question as well? If that is so, you have to implement a dynamical container yourself. I don't see why anyone would want you to waste time on that though, unless it is for homework.
Anyway, what you need to do is
1. use or implement your own dynamical container, such as std::vector
2. make a loop to read the input, using _getch() to read individual characters
3. for each character, check whether it belongs to the input, or indocates the end of input; if input, store it in your dynamical container.
Also, at the end of the program, don't forget to release the memory that you allocated for your dynamical container. std::vector or std::string will do that for you, but if you have your own class, you need to take care of it yourself.
|
|
|
|
|
Hi!
I need to get hash key for a string using MD5 algorithm. How to do this in C++? Where to start?
|
|
|
|
|
Start here[^], just like you always should.
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
If you're implementing your own there's examples all over the net.
If you just want hashes on the Windows platform there's built in Cryptography services: Cryptography[^]
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi All,
How to get the file version information of an MFC excutable.
select properties of an Exe file.
Select File Version tab of exe properties tab
Select File Version Ex.1.0.0.1
I want to get this file version (1.0.0.1) information
how to do this?
|
|
|
|
|
Use GetFileVersionInfo() .
|
|
|
|
|
Hi All,
I want to know the path of an MFC excutable.
Whenever an MFC app is executed, I want to know the path of that executable from where it is executing?
|
|
|
|
|
TCHAR Buffer[MAX_PATH];
DWORD dwRet;
dwRet = GetModuleFileName(NULL, Buffer, MAX_PATH);
"Every Little Smile can touch Somebody's Heart...
May we find Hundreds of Reasons to Smile Everyday... and
May WE be the Reason for someone else to smile always!" (ICAN)
"Your thoughts are the architects of your destiny."
|
|
|
|
|
|
GetModuleFileName() Sometimes returns wrong results when you have a deep directory structure. Use _getcwd() instead. I've used both and experienced the above problem with GetModuleFileName() .
|
|
|
|
|
Hi,
The getcwd function will "get the current working directory" which is not always the same as the directory the process executable is residing in. There are many standard API calls that will change the current working directory of your process. In fact... the CreateProcess function itself has the option of starting your process in an arbitrary working directory.
Best Wishes,
-David Delaune
|
|
|
|
|
getcwd() is not appropriate for this... it returns the current working directory, which can be changed by file open dialogs or any other code that wants to change its working directory.
|
|
|
|
|
The C Runtime to the rescue:
_TCHAR *pszExeFullPath;
int nReturn = ATL_CRT_ERRORCHECK(_get_tpgmptr(&pszExeFullPath));
I use the ATL_CRT_ERRORCHECK() macro to provide some runtime handling of possible CRT errors.
/* Charles Oppermann */
http://weblogs.asp.net/chuckop
|
|
|
|
|
Another way is...
CString appPath = AfxGetApp()->m_pszHelpFilePath;
appPath = appPath.Left(appPath.ReverseFind('\\') + 1);
Tony
|
|
|
|
|
In InitInstance(), member m_pszExeName is your image name. So, use SearchPath() on the result of CString(m_pszExeName) + CString(".exe"). Use the lpFilePart parameter of the call to isolate the path from the file name.
|
|
|
|
|
Hi All,
Program Execution to Invoke() and failes.
....
char buf[200];
OLECHAR *MethodName=L"OpenCurrentDatabase";
OLECHAR *BstrPassword=L"";
HRESULT hret;.
DISPPARAMS params;
VARIANTARG args[3];
BSTR DBLocation=SysAllocString(L"D:\\Example.mdb");
memset(¶ms,0,sizeof(params));
memset(args,0,sizeof(args));
args[2].vt=VT_BSTR;
args[2].bstrVal=DBLocation;
args[1].vt=VT_BOOL;
args[1].boolVal=FALSE;
args[0].vt=VT_BSTR;
args[0].bstrVal=BstrPassword;
params.cArgs=3;
params.rgvarg=args;
hret=d->lpVtbl->Invoke(d,dispid,&IID_NULL,LOCALE_USER_DEFAULT,DISPATCH_METHOD,¶ms,NULL,NULL,NULL);
if(FAILED(hret)) {
printf("Invoke Failed....\n");
sprintf(buf,"Invoke(%08lx) failed w/err 0x%08lx",dispid,hret);
MessageBox(NULL, buf, "Test", 0x10010);
}
...
Debug and find hret's values is 0x80020009.I Inquiry typelibrary:
[id(0x0000094e), helpcontext(0x0000107a)]
HRESULT OpenCurrentDatabase(
[in] BSTR filepath,
[in, optional, defaultvalue(0)] VARIANT_BOOL Exclusive,
[in, optional, defaultvalue("")] BSTR bstrPassword);
Do not know what the problem is. thanks
modified on Tuesday, June 28, 2011 10:36 PM
|
|
|
|
|
yaxiya wrote: Do not know what the problem is. thanks
The seventh argument to Invoke() cannot be NULL , perhaps?
"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
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
I haved add argument ,but failes
|
|
|
|
|
I made a custom CButton::DrawItem() so that I could draw some buttons the way I want them. One of the things I'm doing with it, is making the button "pin-able" to the right side of the parent dialog's (cwnd) display rectangle (using it both as a child to a CDialog and another CButton, in different cases). It seems though, that when a window is maximized, then restored, the restore doesn't call CButton::DrawItem() , leaving my button in the middle of nowhere. If I track the messages, it doesn't seem the framework ever asks the CButton object (or the parent dialog for that matter) to redraw when it is restored.
Seems like maximize and restore are treated differently in the framework. Has anyone seen this before or know how to deal with it?
|
|
|
|
|
Add a handler to WM_SIZE to your parent and use Invalidate or UpdateWindow or somesuch to make your window get redrawn.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<
|
|
|
|
|
I was trying to have the CButton automatically reposition himself within the DrawItem() , that doesn't work too well though (because of the order that the DrawItem() calls are made in) and because WM_SIZE handles some sizing changes different than others. So it was just easier to reposition the button from within the parent if it needs to move (from OnSize() with SetWindowPos() rather than Invalidate() ).
|
|
|
|
|
Thanks for the suggestion though! ...it gave me the idea to finally fix my little problem.
|
|
|
|