|
This is the managed C++ forum, try the Visual C++ forum, where your question will not be off topic.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi all,
Actually i need to create to virtual drive for hard disk. i am trying to fisrt create Disk Image File , then mount this disk image file and use it as virtual drive. Can anybody tell me how to create disk image file or .iso file of any drive.Pls help me. It is highly obliged to me.
Thanks in advance
Bhaskar
|
|
|
|
|
I have used VirtualDrive Pro. It worked very well for me.
Programmer
Glenn Earl Graham
Austin, TX
|
|
|
|
|
Hi,
I'm working in managed c++ and using windows forms and I'm having a problem with Double::TryParse. At a certain point in my work I need to fill a text box with a number ( a double) and when i use Double::TryParse(textBox->Text, number) (where number is of type double), the number i get isn't the double i want.
For example if i fill the text box with "1.2" the variable 'number' will be 12.0 . However if i fill with "1,2" i get 'number' equal to 1.2 (which is the correct result).
My question is if there is any way to make it parse the number in the format "x.x" correctly.
Thanks.
|
|
|
|
|
Hi, your problem is with number formats and regional settings.
In some countries the decimal point is a period, and the optional thousands separator is
a comma. In other countries it is the other way around. Which one your system uses is
choosen through a Control Panel called Regional Settings on an English Windows XP.
Remark: AFAIK the thousands separator is relevant only for output, the character gets
ignored on input.
A program should follow the regional settings as set in that Control Panel, and that is
what a lot of functions/methods do. Some functions/methods also offer an overload
that allows you to specify some options, but I don't expect you find a way to make
TryParse do the opposite of the Control Panel settings.
-- modified at 12:13 Monday 12th November, 2007
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Yes.. But what if I run the program in a computer with different regional settings? Would i have to change the settings in the control panel? =/
And, since, in my program, I have the option to fill automaticaly the textBox through a stored double and it fills in the format "x.x", it wouldn't make sense having to manually change the '.' to a ','.
For Example:
I get a value from a robot ( which my program is controlling) and put it in the textBox (Let's say it's 1.5) It is filled in the form as "1.5". Now I want to feed that number back to the robot (nvermind the reason): the double::tryparse method converts it to 15.0, which is wrong. And it wouldn't be very user friendly do go to the textbox and have to manually change the separator to a comma.
But, nevertheless it worked the problem is that i have to change the settings of every computer in which i use this program :s Thanks anyway
-- modified at 12:59 Monday 12th November, 2007
|
|
|
|
|
Hi,
the normal approach is to use the system settings, they should reflect what the user
expects to have (for all applications).
I trust you can supersede the system settings by systematically use our own settings,
through CultureInfo.NumberFormat.CurrencyDecimalSeparator and others. If this fails at
first, try again, I trust you can get it right in the end.
If you decide to have an app that ignores regional settings, in my opinion you should:
- make sure you are consistent in this.
- mention this on every form that is affected.
Some general advice: an app internally should work with the correct data types,
I mean numbers should be stored and processed as much as possible in ints/floats/whatever
and not in strings. Their string representation should be used only:
- on the user interface (at best following the regional settings)
- on device interfaces, such as a robot: according to the interface spec
- for permanent storage: if binary form is not possible/acceptable for some reason,
then a universal string format should be choosen and documented (here you should NOT
follow regional settings).
BTW: Exactly the same problems exist with dates; there are several date formats,
and in some databases they got stored as strings, leading to all kinds of problems
when the data moves around the world, or gets used internationally.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
UnHolyKnight555 wrote: But what if I run the program in a computer with different regional settings? Would i have to change the settings in the control panel?
That is up to you. If you prefer an English Windows version but you're in front of
a French/Dutch/German/... copy, either you change the settings, or you adapt yourself to
the situation.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Didn't work :s thanks for the response anyway.. I do think it has to do with the culture settings, but didn't find anything that could help me =/ More opinions would be nice :P
|
|
|
|
|
细节问题,中国语,喜欢汉语的外国人可以和我互补学习。claus-santa@hotmail.com
|
|
|
|
|
I am a beginner in C++. I have problem in add a code in VC 2005.
I have a class that used for connection to database, it was write in VC 6 and there was also an example in VC 6.
I had tried to use it in a new project of VC 6, and it's worked.
But when I use it in VC 2005 there is so many error.
If I open the workspace of VC 6 using VC 2005 it will regenerate automatic the source and built it's solution. So it will worked well in VC 2005. So the error won't happen like when I create a new project then add the class.
What should I do the finished this problem, some of the error are :
error C2664: 'strcmp' : cannot convert parameter 1 from 'LPCTSTR' to 'const char *'
error C2664: 'void ATL::CStringT<basetype,stringtraits>::Format(const wchar_t *,...)' : cannot convert parameter 1 from 'const char [84]' to 'const wchar_t *'
error C2440: 'type cast' : cannot convert from 'CString' to 'LPCSTR'
|
|
|
|
|
I believe your problem deals with UNICODE and/or _UNICODE being defined. Unicode is defined by default in VC 2005. To disable undefine the usage of the Unicode character set, you will need to go to the project's property page and change "Configuration Properties/General/Character Set" from "Use Unicode Character Set" to "Use Multi-Byte Character Set".
Also, this should have been posted in the Visual C++ forum.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Thank you very much.
It's working now.
And thank you for told me to posted next time in Visual C++ forum.
|
|
|
|
|
I create a windows form application named p2pport.
and I want to use the Message Map of MFC.
so I use MFC with shared DLL and include afxwin.h.
But When I compile it, it says that
Debug Assertion Failed
File : dbgheap.c
line 144
Expression : _CrtIsValidHeapPointer(pUserData)
I find it is because of the afxwin.h.
I google it and found that it is a bug that was reported to MSDN.
http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=99715[^][^]I use that method to replace the main function and put #include in stdfax.h file.
My original code is
#include "stdafx.h"<br />
#include "Dlg.h"<br />
<br />
using namespace p2pport;<br />
[STAThreadAttribute]<br />
<br />
int main(void)
{<br />
Application::EnableVisualStyles();<br />
Application::SetCompatibleTextRenderingDefault(false); <br />
<br />
Application::Run(gcnew Dlg());<br />
CMFCApp k;<br />
return 0;<br />
}<br />
And I modify it.
<br />
#include "stdafx.h"<br />
#include "Dlg.h"<br />
<br />
using namespace p2pport;<br />
<br />
[STAThreadAttribute]<br />
class CMFCApp : public CWinApp<br />
{<br />
public:<br />
virtual BOOL InitInstance()<br />
{<br />
Application::EnableVisualStyles();<br />
Application::SetCompatibleTextRenderingDefault(false);<br />
return FALSE;<br />
}<br />
}theApp;
But it comes the error.
error C3115: 'System::STAThreadAttribute': this attribute is not allowed on 'theApp'
I delete the [STAThreadAttribute].
It comes another two errors.
error LNK2001: unresolved external symbol _main
fatal error LNK1120: 1 unresolved externals
I dont know how to solve it. I stuck it all day.
Can anybody help me to solve the problem.
Appreciate for ur reply
Thx.
Jane
|
|
|
|
|
There's no Microsoft bug involved here.
If you're going to mix MFC and CLR, you need to make sure the proper
initialization of the CRT and MFC is done.
You also have to think about how Windows messages are going to be processed.
You may want to study the "Using Windows Forms in MFC" section here:
Interop (How Do I in Visual C++)[^]
Is the only reason you're using MFC is to be able to use the message map?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
yes, I only need the message map in MFC.
I want to use MFC in windows form application, not use windows form controls in MFC.
Appreciate ur reply.
Thx.
jane
-- modified at 0:46 Monday 12th November, 2007
|
|
|
|
|
I need to write a simple C program
that prints itself.
now this is real simple only that the files name may change and the program should still work
So I need the code to find out the file's name.
Is there a simple way to access the file's name in C
Tnx a bunch
avatar
|
|
|
|
|
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
wcout << argv[0] << endl;
return 0;
}
Next time, please post this type of question in the Visual C++ forum.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Or see
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
cout << __FILE__<< endl;
return 0;
}
|
|
|
|
|
TCHAR tchFilePath_Name[200];
//Call windows API to get absolute path + file name
GetModuleFileName(GetModuleHandle(NULL), tchFilePath_Name200);
//Then pick-up the file name
//...
|
|
|
|
|
While I thought the use of "ref class" is so memory for ref intantiated objects are always allocated on managed heap. While "value class" are always allocated on stack OR un-managed heap -- however, I must be wrong, "gcnew" can allocate for "value class" as well? Getting confused...
// TestConsole.cpp : main project file.
<br />
using namespace System;<br />
<br />
value class Class1<br />
{<br />
public:<br />
Class1() {<br />
m_pUnmanagedCharString = NULL; << QUESTION 2: How can you init to NULL as you did in MFC?<br />
m_ManagedString = nullptr;<br />
}<br />
<br />
protected:<br />
char * m_pUnmanagedCharString;<br />
String^ m_ManagedString;<br />
};<br />
<br />
int main(array<System::String ^> ^args)<br />
{<br />
Console::WriteLine(L"Hello World");<br />
<br />
Class1* obj = new Class1();<br />
Class1^ obj2 = gcnew Class1(); << QUESTION 1: I thought gcnew is only for "ref classes"!?<br />
<br />
return 0;<br />
}<br />
Thanks!
http://www.codeproject.com/managedcpp/cppcliintro01.asp
http://www.codeproject.com/useritems/quickcppcli.asp
http://www.codeguru.com/cpp/cpp/cpp_managed/general/article.php/c10653/
http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=275&rl=1
|
|
|
|
|
devvvy wrote: QUESTION 2: How can you init to NULL as you did in MFC?
If your code is compiled with /clr, you can use nullptr in the initialization of native pointers, managed handles, and managed interior pointers. You can use NULL with native pointers. However, the usage of NULL can be an issue where it can be interpreted as an integer.
devvvy wrote: QUESTION 1: I thought gcnew is only for "ref classes"!?
Using gcnew on a value type will create a boxed value type that is placed on the managed heap.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Thanks very much but...
George L. Jackson wrote: You can use NULL with native pointers. However, the usage of NULL can be an issue where it can be interpreted as an integer.
If there's an example... please? Also I tried NULL, compiler complained that it doesnt recongnise NULL:
error C2065: 'NULL' : undeclared identifier
George L. Jackson wrote:
Using gcnew on a value type will create a boxed value type that is placed on the managed heap.
Then what's the big fuss with "ref -vs- value"? I thought the primary difference is "ref class" is always allocated on managed heap. AND "value class" is always allocated on stack OR un-managed heap (BUT NEVER on managed-heap). Sounds like they don't need "ref" keyword? Or that by virtue of being a "ref class" the object can NEVER be allocated on stack or un-managed heap?
Is that what it is?
devy
|
|
|
|
|
devvvy wrote: If there's an example... please? Also I tried NULL, compiler complained that it doesnt recongnise NULL:
NULL must be defined first: #define NULL 0 .
NULL is defined in stdio.h as zero (0).
devvvy wrote: Then what's the big fuss with "ref -vs- value"? I thought the primary difference is "ref class" is always allocated on managed heap. AND "value class" is always allocated on stack OR un-managed heap (BUT NEVER on managed-heap). Sounds like they don't need "ref" keyword? Or that by virtue of being a "ref class" the object can NEVER be allocated on stack or un-managed heap?
Is that what it is?
Value types (which includes value class ) don't use constructors for default initialization. The value type's fields are initialized to zero (or nullptr if it is a managed handle). A value type can be copied by value with less overhead than a ref class. Value types can be stored and initialized with less overhead in an array or collection than a ref class. You can copy value types using only the equal sign.
-- modified at 20:52 Sunday 11th November, 2007
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Thanks George
George L. Jackson wrote: NULL is defined in stdio.h as zero (0).
I suppose I should readup on interop, thanks.
George L. Jackson wrote:
Value types (which includes value class) don't use constructors for default installation. The value type's fields are initialized to zero (or nullptr if it is a managed handle). A value type can be copied by value with less overhead than a ref class. Value types can be stored and initialized with less overhead in an array or collection than a ref class. You can copy value types using only the equal sign.
I thought you can do all these with "ref class" --- equal operator depends on whether you've implemented it. And all fields are initialized to either zero or nullptr - that'd be default behavior for both "ref class" and "value class"...
devy
|
|
|
|