|
Hi,
yeah, the forum structure (and their names) may confuse you:
the regular C++ language, the only C++ Visual Studio supported up to version 6,
and still supported by newer VS versions, is handled in the "Visual C++/MFC" forum.
This seems the one you need this time.
the extended C++ language that runs on top of the .NET Framework and uses all the
nice .NET classes, is handled in this, the "(Managed) C++/CLI", forum. It requires
Visual Studio 7 or better.
C# is always managed, and has its own forum.
old VB and new VB.NET are both handled in the one "Visual Basic/VB.NET" forum.
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
|
|
|
|
|
|
Either the user running your application needs to be given permission on the shared folder, or you would have to impersonate a user who does have permission. This[^] article describes impersonation in C++.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Hi, I'm using Visual Studio 2005 C++/CLI. I have a double value of 4.000000000000000 that I subtract 0.2 from leaving 3.7999999999999998. I want to round this to 3.8 so I use 'double rounded_value = System::Math::Round(value_to_round, 2)' where the resulting value is exacly the same at 3.7999999999999998. In the next iteration I subtract 0.2 from the rounded value of 3.7999999999999998 leaving 3.5999999999999996. Then the Round() function results in 3.6000000000000001. After subtracting 0.2 from this I get 3.3999999999999995 and the Round() function results in 3.3999999999999999. If I use the Round() function to round to an integer it works fine, but this rounding to 2 significant digits is not working. Anyone know why?
Thanks
Buck
|
|
|
|
|
According to Microsoft's documentation:
Return Value:
The number nearest value with a precision equal to digits. If value is halfway between two numbers, one of which is even and the other odd, then the even number is returned. If the precision of value is less than digits, then value is returned unchanged.
Also:
The digits parameter specifies the number of significant digits in the return value and ranges from 0 to 15. If digits is zero, then a integer is returned.
The maximum total number of integral and fractional digits that can be returned is 15. If the rounded value contains more than 15 digits, the 15 most significant digits are returned. If the rounded value contains 15 or fewer digits, the integral digits and as many fractional digits as the digits parameter specifies are returned.
The behavior of this method follows IEEE Standard 754, section 4. This kind of rounding is sometimes called rounding to nearest, or banker's rounding.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
I went ahead and used a Decimal type to get around this, but I thought the number of significant digits was the number of digits to the right of the decimal point... 1.0 is one significant digit, 1.00 is two significant digits 1.000 is three significant digits and so on. But it doesn't matter what you use for the digits parameter. A digits parameter of 0 does return an integer but a digits parameter of 1 to 15 always returns fifteen significant digits.
|
|
|
|
|
You'll always get the nearest value representable by the Double type.
This won't always be exactly what you expect.
The Round() method is not used the same way a string "Format" method may be used to
round a floating point variable to a string for display.
If you want to play with some floating point variables at the bit level, you may
want to check out Joe Newcomer's Floating Point Explorer[^]
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi Buck,
the way floats/doubles are stored in binary makes it impossible to exactly represent most
values, especially the ones that seem like round numbers to humans thinking using base ten.
So 4, 2, 1, 0.5, 3.5, 3.75 and many others are representable exactly (basically since
they all equal an integer divided by some power of 2); but 0.2, 3.6 and 3.8 and an infinite
number of other values are not.
Now whatever float/double function you call, if it returns a float/double will suffer
from the same phenomenon. So the only way to really get "3.6" or "3.8" is by using a
function that not only rounds but returns a string. I trust there are some formatting
methods that do just that in C++; ToString() should be one of them, given an appropriate
format specifier.
BTW: to circumvent this problem, especially for monetary numbers, they introduced
the "decimal" data type (which basically stores decimal digits). Maybe that's what you
need in your app.
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
|
|
|
|
|
Good reply Luc!
There was a lengthy thread on the MSDN VC board about this recently
that was entertaining.
Cheers!
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi, I'm using Visual Studio 2005 C++/CLI. This isn't critical but it would be nice to do. I have an app that uses SaveFileDialog^. When the application runs without breakpoints the dialog pops onto the top of the screen as expected, but when I'm debugging the dialog box sometimes ends up invisible until I minimize all other windows. Is there a way to set the dialog box's location and weather it will always be on top.
Thanks,
Buck
|
|
|
|
|
Hi,
you could pass your calling form ("this") to the dialog using this overload:
public DialogResult ShowDialog (IWin32Window owner)
That should keep your dialog on top of the app, so clicking anywhere in one of the app
windows should make the dialog topmost again.
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
|
|
|
|
|
Thanks Luc, I printed this off for my notes, I never would of thought of that.
|
|
|
|
|
Hi.
In the project that I am working, I need to develop a listener that checks a folder and files.
Well, on CLIENT this listener will have detect ANY internal change in ANY file in the folder and instantly will synchronizer with SERVER, like a ShadowCopy, and different of a snapshot, for keep integrity between CLIENT-SERVER, ok?
Can anyone give me a hand? Libraries, and similar components.
I'm working in c++ builder, but visual studio components also help.
Regards,
Caetano Nunes Almeida
|
|
|
|
|
In Visual Studio there is filesystemwatcher component to monitor folder for changes.
|
|
|
|
|
He is looking for a "native" C++ solution (He is in the wrong forum), and he has cross=posted.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Please don't cross post and post in the wrong forum.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
hi everyone,
how can i import a dll file in c++ ?
there are millions of pages telling this story for c# on the internet.
but i couldn't find something useful for c++.
would you please write me some code? or point me some link that contains valuable information about the thing i am asking for.
thanks in advance.
MFA
|
|
|
|
|
Do you mean LoadLibrary() or #import ?
|
|
|
|
|
Hi all,
I got a small trouble, If some one know how to do please tell me, many thanks.
I want to assign szData value into textBox->Text, but two kind of variable different type.
I used Visual Studio 2005, and developed VC++ language.
<br />
private: System::Windows::Forms::TextBox^ textBox;<br />
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { char* szData = "abcabcabcabc";<br />
textBox->Text =
}
|
|
|
|
|
Do you need to use "char*" in managed code?
How about this:
private: System::Windows::Forms::TextBox^ textBox;
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e)
{
String ^str = "abcabcabcabc";
textBox->Text = str;
} or without the extra assignment...
private: System::Windows::Forms::TextBox^ textBox;
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e)
{
textBox->Text = "abcabcabcabc";
}
Mark
Last modified: 20mins after originally posted --
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
How about something like this?
textBox->Text = gcnew String(szData);
|
|
|
|
|
<br />
textBox->Text = gcnew String(szData);<br />
Yeah, This way I realy like. Can you introduce more about this. How can you find out this way?
Do you have any tips for this kind?
Sorry, my English very bad.
|
|
|
|
|
Well it's quite simple:
You can create String objects with passing char* to the String constructor.
'Text' is something like pointer. gcnew is something like new in c++ but a little bit smarter. So all we have to do is just create new String^ object with szData as value instead of "" ( String is initialized with "" string normally ).
|
|
|
|
|
Hi,
I am compiling old C++ code in visual studio 2005. I am Getting the error as fatal error LNK1104: cannot open file 'libc.lib' ASMUtils
libc.lib
I found this library is not avialable in VC8. I copied this library from VC7 but still I am getting many other errors.
Even I tried to ignore it by putting Linker-Input-Ignore Specific Libary, but I could not able to fix this bug
Need some urgent help.
Thanks in advance
|
|
|
|
|
This is my code below: It gets the computer name and then the associated IP along with it. If we have the IP address how can we get the computer name? Thanks
void AsyncServer::InitSocks()
{
String* server = "CATUXPSD01";
int port = 4901;
printf("in InitSocks");
String* request = String::Concat(S"Our test data asdf");
Byte bytesSent[] = Encoding::ASCII->GetBytes(request);
Byte bytesReceived[] = new Byte[256];
Socket* s = 0;
IPHostEntry* hostEntry = 0;
// Get host related information.
hostEntry = Dns::Resolve(server);
//hostEntry = new IPHostEntry();
// Loop through the AddressList to obtain the supported AddressFamily. This is to avoid
// an exception that occurs when the host IP Address is not compatible with the address family
// (typical in the IPv6 case).
IEnumerator* myEnum = hostEntry->AddressList->GetEnumerator();
while (myEnum->MoveNext())
{
IPAddress* address = __try_cast<ipaddress*>(myEnum->Current);
IPEndPoint* endPoint = new IPEndPoint(address, port);
Socket* tmpS = new Socket(endPoint->AddressFamily, SocketType::Stream, ProtocolType::Tcp);
try {
tmpS->Connect(endPoint);
}
catch(Exception *e) {
// Handle exception here
}
if (tmpS->Connected)
{
s = tmpS;
break;
}
}
// Create a socket connection with the specified server and port.
if (s == 0) {
printf("Connection failed");
} else {
// Send request to the server.
s->Send(bytesSent, bytesSent->Length, static_cast<socketflags>(0));
}
}
|
|
|
|