|
I should also say i've tried: sscanf(CString,"%f",&float) which from what I have read on the web should be able to take CStrings but the compiler (MS Emmbedded visual C++ 3.0) tells me: cannot convert parameter 1 from 'class CString' to 'const char *'" so i've tried other ways to convert CString to LPTSTR and char[102] but i'm stuck. I can't think of what else to try. please help.
In VB all I used was something like: float = CCur (string)
I'm sure its not all the had in C++ but it seems to have me beat!
Thanks in Advance.
Jochum Wittebrood.
|
|
|
|
|
CString has a method to return the underlying char*, which you can then pass into atof. From memory, it's something like LockString, and you need to call a corresponding Unlock method when you've used the char * for whatever dastardly deed you intend. std::string has the c_str() function which does much the same thing. Sorry, it's too long since I lived in MFC land, I don't know the specific function you want. Hopefully this is enough to push you in the right direction
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
I've had a look through the help docs for functions like that, but I can't find anything that I can get working. I can't find anything on LockString or c_str() maybe i'm not looking in the right places... It shouldn't be this hard should it?
Jochum
|
|
|
|
|
Jochum Wittebrood wrote:
It shouldn't be this hard should it?
WElcome to MFC....
The methods are GetBuffer and ReleaseBuffer.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
|
simple mathematic operations you say ?
look at this[^]
TOXCCT >>> GEII power
|
|
|
|
|
Use the generic C Runtime function _tstof() .
See MSDN for more info...
Hope this helps...
Mike
|
|
|
|
|
Thanks for all your help guys, but I tried all the functions that you suggested and they all require 'const char' where the CString seems to be 'unsigned short'. The compiler always gives me convertion errors...
It must be my VB background but I can't seem to get my head around this, while people must use it in code all the time. Does anyone have a small snippit of code to show me how they do it?
This is what I've got...
int ListIndex;
CString WorkingStr;
CString TempStr;
float TAG;
CListBox * List1=(CListBox *)GetDlgItem(IDC_LIST1);
ListIndex = List1->GetCurSel();
List1->GetText(ListIndex,WorkingStr);
TempStr = WorkingStr.Mid(54,8);
TAG = atof(TempStr);
So we know that last line is the problem, but what can I do to fix it?
Thanks for your help.
Jochum
|
|
|
|
|
Hello,
I know how to change the dropdown width of a combobox during runtime, but does anyone know how to change the width of the actual combobox at runtime?
Thanks,
Murrah Boswell
|
|
|
|
|
The combo box is the actual control, and the drop-down list box is a child of the combo box.
- To set the width of the list box, send a CB_SETDROPPEDWIDTH message (Win32) or call CComboBox::SetDroppedWidth (MFC).
- To set the width of the combo box control, call SetWindowPos (Win32) or CWnd::SetWindowPos (MFC).
Hope this helps you out.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Thanks for the replay,
How do I get the CWnd handle of my ComboBox?
Murrah Boswell
|
|
|
|
|
Disregard CWnd question, I figured it out!
Thanks for your help,
Murrah Boswell
|
|
|
|
|
GetDlgItem(MY_COMBO)
TOXCCT >>> GEII power
|
|
|
|
|
Hi, I've created a linked list and in my C++ source file I'm creating objects and passing them to a linked list in a loop. I want to loop over the linked list to show that the values are actually in the list. How would I do this?
I've uploaded all the code here if you want to take a look: http://www.hostmaster-x.co.uk/c++/
Thanks in advance for any help.
Cheers,
lordmickel
|
|
|
|
|
If this is not homework, why are you not just using the list class included in C++ ?
Otherwise, just grab the first item, and keep stepping through the list, printing out each item as you go, or whatever else your homework requires. The code you've commented out looks like it should work, if your list is working.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Christian, thank you for your reply. This is homework - kind of. I'm not taking classes as such, just dabbling a little. From what you have said it would seem that the list isn't working correctly because when I uncomment the code I get the following output:
Please enter the driver's name then press enter:
driver1
name = driver1
driver2
name = driver2
driver3
name = driver3
name 1:
name 2:
name 1:
name 2:
Press any key to continue
Any ideas what the problem could be?
Cheers again,
lordmickel
|
|
|
|
|
lordmickel wrote:
This is homework - kind of. I'm not taking classes as such, just dabbling a little.
Cool - I applaud that you're writing your own list then. Once it works, you'll understand how they work, and you should then use the STL exclusively
What happens when you step through the code in the debugger ? Are your values getting stored correctly in the list ? What about the pointer values as you step through, where do they go ?
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Thank you, thank you! ........ I'm not really familiar with stepping through the code, MS VC++ doesn't seem to be too helpful - or perhaps its just me. Unfortunately I can't really answer any of your questions exactly.
When I ran the debugger, the command prompt popped up and began running the program. When it had finished it produced this:
Loaded 'ntdll.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\kernel32.dll', no matching symbolic information found.
The thread 0xF9C has exited with code 0 (0x0).
The program 'C:\Program Files\Microsoft Visual Studio\MyProjects\text_class\Debug\text_class.exe' has exited with code 0 (0x0).
Is there a better, more user friendly compiler that I could use that would be able to step through the code properly? I can't seem to get VC++ to do it
Thanks again,
lordmickel
|
|
|
|
|
lordmickel wrote:
Is there a better, more user friendly compiler that I could use
No.
lordmickel wrote:
that would be able to step through the code properly? I
The problem is not the compiler
Use F9 to set breakpoints ( they look like a big black circle on the left margin, make sure you're building a debug version and hit F5. Then VC++ will stop at the breakpoint and allow you to step through the code, set and check variable values, etc.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
If you need to 'prove' that certain elements (an element of a list contains a value and a pointer to the next element) are members of a list, then the most effective way is to start from the header element and print the value of the 'next' pointer, which is the address of the next element. Then you would move into the next element, print it's address (which resolves to the same as the 'next' pointer on the previous cell), and print the value of this new element's 'next' pointer and move on again, repeating the process.
This will bring forth an effective way to prove that certain elements are linked to each other. It will not work for circularly linked lists, because the loop would never end. For a non-circular list, the last 'next' pointer is a NULL value.
However, I see no reason in 'proving' that the elements are members of a list. Why would anyone need to do such ? Isn't it enough if the list fills it's purpose, whatever that purpose might be ?
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Antti, thank you for your reply. I had set something like that up in my classes but something isn't working correctly. I'm just doing this to prove that the list works - which at the moment it doesn't. Thanks for the circular linked list tip.
Thanks again,
lordmickel
|
|
|
|
|
Your first problem is that you are not storing valid pointers in your list. Try replacing the load code with,
details * driver = new details ;
driver->enter_driver_name();
output.DisplayDriverName(driver->get_name());
list.add_driver(driver);
And to print the contents try,
details* pDriver = list.getFirstDriver();
while ( pDriver )
{
cout << "name: " << pDriver->get_name() << "\n" << endl;
pDriver = list.getNextDriver () ;
}
Note I haven't suggested changed anything in your details or list classes which are basically working... Although you haven't made any attempt to manage memory, a 'package' should probably be able to delete a 'details' and a 'driver_list' should probably have a destructor that deletes all the packages.
Paul
|
|
|
|
|
Paul, please forgive me for the extremely late reply. I've changed the code and it works perfectly, thank you so much for your very helpful reply!
Thank you,
lordmickel
|
|
|
|
|
Does anyone have ideas on how i can retrieve the following system information:
1. processor serial #
2. hard-disk serial #
Thanks
larry_larry
|
|
|
|
|
GetVolumeInformation() will get you a disk's serial number.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|