|
I have bought a book Visual c++ NET 2003. All things are not there.
There is no book that treat all matter.
Now I say you, I make a programme in Visual c++ Net 2005,but I need to improve it .
Don't discourage me Sir.
I learn like that Viual c++ MFC, I wrote 4 Programs that are running up to now in many businesses.
And now I am converting those programs in Visual c++ NET. I have no the same things than in MFC. And I have only one book up to now
|
|
|
|
|
mikobi wrote: There is no book that treat all matter.
Correct, that's why I said you need a C++ beginners book. Not a book specific to Visual C++ for .NET. Most of those books are going to expect a basic knowledge of C++.
My first University course was titled Programming logic and design. There was no compiler and no language, it was about learning how computer systems work and how the hardware provides a logical foundation for software development. Without a similar foundation trying to learn C/C++ is going to be far more difficult. My point is that starting at the beginning is the far better choice.
Good luck
led mike
|
|
|
|
|
Questions I ask are not logic questions but Syntax because specific to this language. What I ask, I have done it In Visual C++ MFC. But Now it is a new language that I learn.
Mister, What is the forum important if we cannot asked what we don't know.
|
|
|
|
|
In Visual c++ NET 2005, I don,t know how to have an handle to the specified menu because there is no Identification like IDC_File and so on .
This function is written where
|
|
|
|
|
Hi,
I am currently converting my VC++ project to mixed mode by enabling /clr.
But i am getting a 'System.IO.FileLoadException' in DeBug and not in Release mode, with the following information:
An unhandled exception of type 'System.IO.FileLoadException' occurred in Unknown Module.
Additional information: Could not load file or assembly 'MyProj, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. Could not find or load a type. (Exception from HRESULT: 0x80131522)
Please could someone help me to resolve this....
Regards
RMR
|
|
|
|
|
Rinnu Mary wrote: in DeBug and not in Release mode,
Difficult to do anything but guess based on the information you provided. Project settings are likely missing something for the Debug version of the settings. Maybe the reference to this 'MyProj' assembly?
led mike
|
|
|
|
|
Hi Rinnu,
Rinnu Mary wrote: An unhandled exception of type 'System.IO.FileLoadException' occurred in Unknown Module.
Copy the file you are trying to open into either PWD or the \Debug folder (I can never remember which...).
Rinnu Mary wrote: Additional information: Could not load file or assembly 'MyProj, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. Could not find or load a type. (Exception from HRESULT: 0x80131522)
I believe you are getting this because you are not catching the exception.
Jeff
|
|
|
|
|
Hi Rinnu,
I was not paying close enough attention to details... I thought I read FileNotFound exception.
Jeff
|
|
|
|
|
We ran into something that might have a bearing on this. The problem ran into was that we were getting a new library from a third party.
The developer installed it on his workstation, tested it, fixed a couple of bugs in our code and then check the project back in.
The problem is that we did not accept the library for production and he had unreference the third party library and rereferenced the new library before the check in, our build system still had the older library so it was producing broken builds.
|
|
|
|
|
Hi All,
The code below throws an exception in the finally block ('Cannot access a closed stream'). According to CryptoStream Class[^], I must call Close() on the CryptoStream. I've tried closing the inner stream first, and the inner stream last. What is the proper order/method for closing the streams?
Jeff
* Also note that if I only close the CryptoStream, no exception is thrown.
TripleDESCryptoServiceProvider^ tdes =
gcnew TripleDESCryptoServiceProvider();
...
StreamWriter^ writer;
CryptoStream^ crypto;
MemoryStream^ memory;
try
{
writer = gcnew StreamWriter(
crypto = gcnew CryptoStream(
memory = gcnew MemoryStream(),
tdes->CreateEncryptor( key, iv ),
CryptoStreamMode::Write
)
);
writer->Write( ... );
}
catch( System::Exception^ e )
{
Console::WriteLine(L"CLR Exception: {0}", e->Message);
}
finally
{
memory->Close( );
crypto->Close( );
writer->Close( );
}
|
|
|
|
|
Have you tried a hammer?
I have never worked with this stuff outside of research but don't recall having a problem. Since it's telling you ('Cannot access a closed stream') it seems it already is closed and therefore you don't need to close it. Have you tried that?
I would be interested in knowing the answer to this.
led mike
|
|
|
|
|
Hi Mike,
led mike wrote: I would be interested in knowing the answer to this.
I _think_ I found the answer - it's a question of ownership. Apparently, Microsoft's object claims ownership to the streams (which they did not open). I've read through the documentation on the various ctors and Close() methods, but I must have missed who owns what.
I like unmanaged code better . At least with unmanaged, I could fire up WinDbg and walk in, observing what is happening. With managed, I get an error about attempting to set a breakpoint.
Others have asked this question also. In an MSDN blog, the BCL team (owner of System.IO) claims objects should only dispose of streams they create [1]:
The default behavior of a class that takes a Stream in it’s Constructor is to also be IDisposable and close the stream when the wrapper is closed. So, if I am reading this correctly, I am responsible for StreamWriter. When I call Close() on the StreamWriter, it will close the CryptoStream and Memory Stream.
I believe the following listing is correct (at least its behavior is not throwing exceptions). I should only close the outer most object. If an exception occurs, close the CryptoStream (as per the documentation of CryptoStream) and let the CLR clean up the rest. So, to summarize:
1) I hold the StreamWriter^ writer because I call Close() on it if all goes well
2) I hold the CryptoStream^ crypto because I call Close() on it if anything fails.
3) I hold the MemoryStream^ memory because I need to do something with the cipher text stream/byte array if all goes well _before_ I call Close() on the StreamWriter
Finally, I believe Microsoft's example on MSDN is incorrect [2]. I suspect it will throw the exception 'Cannot access a closed stream' also. But I did not attempt to run their code.
Jeff
StreamWriter^ writer;
CryptoStream^ crypto;
MemoryStream^ memory;
try
{
writer = gcnew StreamWriter(
crypto = gcnew CryptoStream(
memory = gcnew MemoryStream(),
tdes->CreateEncryptor( key, iv ),
CryptoStreamMode::Write
)
);
writer->Write( ... );
}
catch( System::Exception^ e )
{
crypto->Close();
Console::WriteLine(L"CLR Exception: {0}", e->Message);
}
finally
{
writer->Close( );
} [1] Should I close the stream?[^]
[2] CryptoStream Class[^]
|
|
|
|
|
Yeah, that's what I thought, thanks for posting your findings.
led mike
|
|
|
|
|
Hello,
I am porting an unmanaged console application to windows app using Visual Studio 2005 C++ Express. I worked with Visual C++ and MFC before but this is my first time to use .NET and Windows form in C++. I was able to create the windows GUI on Windows form easily. My problem is for the function in unmanaged DLL to print out the message in my Windows form. I've seen a few blogs and discussions about the managed C++ code to unmanaged code. But I have not seen yet about my particular problem which is unmanaged to managed. Again, here is my specific problem.
1. I've created a textBox in Windows form and set the property to read only.
2. I developed a wrapper function that the unmanaged DLL will use to print its message.
3. How can my wrapper function access the textBox from the Windows form to print the message?
4. Do I need to add a public method in my windows form class to access the private textBox method/property?
I appreciate the help and thanks.
Manny
|
|
|
|
|
You can't call managed code from unmanaged code.
You can, however, call managed code from native code that is compiled to CLR.
If the DLL is not a .NET assembly (all native - none of it is compiled with /CLR) then you'll need to expose a
native method somewhere for the DLL to call. Maybe that's what you already have in item 2 (see question below)?
Manny Roxas wrote: 2. I developed a wrapper function that the unmanaged DLL will use to print its message.
Is this function in the DLL or the app?
Is the DLL a managed or mixed-mode assembly or pure native DLL?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark,
Thanks for your reply. To answer your question, the wrapper function is a managed code in the app. The DLL is compiled in VS 2005 C++ as "No CLR support". But even without the DLL, just my Windows app and wrapper function, I need to know how my wrapper function access the textBox in my Windows form. I need to get the instances of my Windows form or its handle. But I don't know how to do it in .NET.
Manny
|
|
|
|
|
Managed handles can be moved at any time, so to keep a managed handle around
for use by unmanaged code, you can use the GCHandle Structure[^].
There's a handy template wrapper for GCHandle called gcroot[^] that you can use to
simplify the code.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi Mark,
What I really want to do is declare the Form handle as global or public as shown below so I that my wrapper function can access it. My wrapper function is still a managed code. Can I do that? I was told that it can be done in Visual Basic.
Form1 ^MyWindowsForm = gcnew Form1();
Thanks,
Manny
|
|
|
|
|
I still recommend reading those links to understand what's going on.
The simplest syntax is using gcroot, which hides some messier code used
when using GCHandle directly...
#include <vcclr.h>
gcroot<Form1 ^> MyWindowsForm;
...
MyWindowsForm = gcnew Form1();
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I got it. Thanks, Mark.
Manny
|
|
|
|
|
Can anyone suggest a good book for C++/CLI??
I dont find much books in the market though...
Strange!!
And I heard somewhere that CLI is the most powerful language!!
I need a book with imtermediate skills..
Although I am a beginner, still I think I can learn those basics from internet..
So any help to get a good intermidiate C++/CLI book will be highly appreciated..
Thanks!!
|
|
|
|
|
wrote: CLI is the most powerful language!!
CLI means Common Language Interface. It is not an actual programming language, but rather a set of classes that make up the .NET Framework.
"I guess it's what separates the professionals from the drag and drop, girly wirly, namby pamby, wishy washy, can't code for crap types." - Pete O'Hanlon
|
|
|
|
|
Nishant Sivukumar has an excellent book on the topic, it's published by Manning.
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 )
|
|
|
|
|
Christian Graus wrote: Nishant Sivukumar has an excellent book on the topic, it's published by Manning.
I've seen Nishant's book..
Its really excellent, but it is not for intermediate developers..
It teaches interop capabilities and WPF,WCF which I think is relevant for advanced developers..
Anyways, thanks for your help..
If anybody else knows an intermediate level book please let me know..
Thanks again..
|
|
|
|
|