|
Richard MacCutchan wrote: talk to your client
People really do such things?
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
|
|
|
|
|
what to talk , he needs managed code thats it. I must make it to work. What all I need to do if anyone knows please tell me to make the code managed. ??
|
|
|
|
|
sujandasmahapatra wrote: he needs managed code thats it.
This is ridiculous. Ask your client what exactly he is looking for. If he says "I want managed code" then ask again: for what reason. You are never going to be able to solve this problem until you know what problem you are trying to solve. Managed code in itself is not an answer to anything, in some cases it is even a bad answer.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
sujandasmahapatra wrote: what to talk
Because you need to know exactly what he wants to get accomplished. Is he going to pay you to rewrite your unmanaged code to managed code? Why does he think he needs managed code? Does he think that managed code is going to give him some benefit that doesn't exist? Or does he want managed code just because he heard a buzzword?
sujandasmahapatra wrote: he needs managed code thats it
That is not it. You have unmanaged code already and you seem to think that adding the /clr switch is going to magically transform the unmanaged code to managed code. It is not.
sujandasmahapatra wrote: make the code managed
If you want managed code you have to write is as managed code. You cannot add a switch and make your MFC code suddenly managed. the /clr switch allows you to mix the two not transform one to another. Your unmanaged code will still be unmanaged.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
|
|
|
|
|
We have successfully used MFC and C++/CLI Managed code in the same project/executable so it's certainly possible.
We are creating WPF windows just fine from C++/CLI code and can also use much of the legacy MFC code alongside. We stopped using Doc/View architecture in favor of WPF so that will be much of the work to-do if you want to use WPF.
Here's some of my advice from what I recall of the early days:
1. Separate which files need to have managed code and which are native-only. For the managed files, only mark them as /clr. Do this on a .cpp file-by-file basis.
2. In your MFC applications' InitInstance, create an instance of a .NET application object (ex. gcnew MyNetApp(); ) and keep that in an accessible singleton.
3. In your MFC application class Run() function, call the .NET application's Run.
ex. return MyNetApp::Instance->Run();
4. Change project settings for Code Generation to Enable C++ Exceptions with /EHa on the managed files (may be fine to use that for all files).
John
|
|
|
|
|
Yoa are better to throw the MFC code to garbage if you really need managed code. You won't be able to use MFC in a fully managed application thus you would have to uses mixed mode. But if you use mixed mode, then you can just have some part managed and some not managed.
If you really want a managed application, the best thing to do would be to start a new application using WinForms or WPF, and then redo all the UI and then port your code.
You have to understand that MFC and .NET are two worlds. While you can host managed controls in a MFC dialog (or an ActiveX control in a .NET application), you won't be able to cretae a fully managed application.
In a word, without using mixed mode (that is keep MFC not managed and eventually uses some managed .NET controls), the effort to port the code to be managed will probably be higher than completly rewrote the application. It simply does not make any sense. Show to your client our answers and tell him you would have to rewrote the application. If the application is large, it can take months or even years to do so.
If you try anyway, you will probably loose months trying to make things works and still have a lot of problems.
By the way, if you use MFC DLL, then you application have to be compiled with options that are compatioble with MFC. If you use .NET, then your application need to be compiled with options that are compatible with .NET.
If you try to uses both, you will have a lot of incompatible options and you will have to select proper options on a file by file basis. You will probably also need to have 2 set of precompiled header. One for unmanaged stuff and one for managed stuff.
I have done so code where I want to have some managed code and some unmanaged code, and I have to uses some custom options. I have a lot of warning for header files that are sometime included as managed and sometime as unmanaged as some definitions are differents. The more you application is complex, the more it will be hard to fully understand all the implications and the more, you will have hard to debug problem caused by things like incompatible macros definitions, incompatible alignments that will cause your application to crash at run-time. You will have to fully understand the implication of any compiler and linker options. In my case, it was something relatively simple so I was able to manage incompatibilities. By the way, I think I also need some tricks to get DLLs proberly loaded in my case.
If your client want managed code because the code run in a secure environment like SQL, then I think the only option is to rewrote the application.
In the end, you either have to tell your client it is not possible or that you have to rewrote your application. And rewroting the application, even if it is easier in .NET might take probably at least half the time it take to make the original application depending on how the application was done.
If you uses some advanced C++ stuff like template, boost, STL and you want a fully managed application (not mixed mode) it can even be harder to port the application. You can always uses STL/CLR to replace STL but even there you have a lot of changes to do.
In a fully managed application, you won't be able to uses pointers... And if you use mixed mode, then why not have some DLL managed (mixed mode) and some not managed (existing MFC code). That solution will be much more simpler.
Philippe Mori
|
|
|
|
|
value class ValBase
{
public:
int a;
};
ref class RefBase
{
public:
int a;
};
int main(array<System::String ^> ^args)
{
RefBase^ RefBase1 = gcnew RefBase; ValBase^ ValBase1 = gcnew ValBase;
RefBase* RefBase2 = new RefBase; ValBase* ValBase2 = new ValBase;
}
In the last assignment where is the managed object stored ? I am totally new to C++ CLI.
Also, is it true that value types should use stack semantics to make code efficient ? i.e instead of ValBase^ ValBase1 = gcnew ValBase, I should just use ValBase ValBase1;
|
|
|
|
|
ValBase2 is stored on the unmanaged heap since you are using new instead of gcnew. Thus, you will have to explicitly delete it: delete ValBase2; .
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Thanks George. So, is there any way for a Native pointer to point to Managed Heap. I know this is not the correct thing to do but is it possible ? An example would be appreciated. I also think there is no way for a Handle (^) to point to native heap, is this correct ?
|
|
|
|
|
The GCHandle class could help you out.
|
|
|
|
|
The native pointer can point to any address. Please explain why you want to use native pointer to managed resource? It is very incorrect way. I think you should change your architecture instead of making such a thing. If you want to call managed code (method of managed object) from unmanaged context you should use callback.
Handle can not point to native heap, but IntPtr can.
|
|
|
|
|
Hi,
I have an ActiveX dll compiled in visual studio 2003. and it was working fine with the IE .Recently i have build the activex with VS2005. The same activex works fine now also. But it is showing ATL 8.0 on the center of IE.
Note: this activeX dose not have UI.
Can any one know whats went wrong with VS2005? I know VS2005 has ATL 8.0 version.
Thanks in advance.
Birajendu
SonicWALL
Bangalore
India
|
|
|
|
|
The ATL version # is painted by the default OnDraw of CComControlBase (see OnDraw in atlctl.h). So whether you know it or not, you've created a visual control. So you should either override OnDraw yourself and simply return S_OK or change your object derivation to truly be a non-visual control.
|
|
|
|
|
Thanks a lot...
The solution provided by u has been worked for me.
Birajendu
SonicWALL
Bangalore
India
|
|
|
|
|
Form1 creates the webBrowser with this code:
this->webBrowser1->AllowNavigation = false;
this->webBrowser1->Location = System::Drawing::Point(57, 102);
this->webBrowser1->MinimumSize = System::Drawing::Size(20, 20);
this->webBrowser1->Name = L"webBrowser1";
this->webBrowser1->Size = System::Drawing::Size(250, 140);
this->webBrowser1->TabIndex = 3;
this->webBrowser1->Url = (gcnew System::Uri(L"about:blank", System::UriKind::Absolute));
I have a series of “Do This” buttons on the main form.
I want to be able to clear the web browser window as each button is clicked so the browser control only displays the result of the last button that was pressed.
As a test, I am calling this Html Line method 5 times. Each call should clear the box and display only the last html line. I’ve tried multiple ways to clear the box, nothing works. At the end of the process all 5 lines are displayed.
What is the proper way to define a web browser box so I can clear it and refill it at will?
System::Void Feedback::HtmlLine ( String ^ showLine )
{
if ( webBox == nullptr)
return;
webBox->DocumentText = ""; webBox->Navigate("about::empty"); webBox->Document->Write(showLine);
webBox->Refresh();
String ^ fullDisplay = webBox->DocumentText;
int count = 1;
return;
}
|
|
|
|
|
in your first snippet, it is all about webBrowser1 .
in your second snippet, it is all about webBox .
If those are distinct, then you're probably looking at one while modifying the other; and if they aren't distinct, you should not have two variable names for the same thing. Cleaner code yields fewer problems.
|
|
|
|
|
My suspicion is that you need to wait for the Navigate to finish before doing the Document->Write since Navigate is an asynch operation as I recall. Try moving the code after ->Navigate into a handler for webBox->Navigated event.
|
|
|
|
|
First note that it should be "about:blank" not "about::empty". There is just one colon, not two, and use blank instead of empty. You can try all those out in a browser window and if you do I think you will see that you need to use "about:blank".
Next, yes; you must wait for the navigation to complete. The common way to do that is to handle the DocumentComplete event. That event is used so much that it is the default event for the WebBrowser control. In other words, if you double-click on the WebBrowser control in the designer, then a handler for the DocumentComplete event will be automatically added.
I am not sure how to clear the page when you use Write to write HTML. What I would do in my DocumentComplete event handler is to use:
webBrowser1->Document.Body.InnerHtml = showLine;
I have been using C# more than I have been using C++ lately so that syntax might be incorrect but I assume you can fix it if needed.
Note however that you need to wait for the document to be complete only once; after that, you can change the HTML without waiting, but you might need to wait for DocumentComplete event if you need to immediately use the document.
|
|
|
|
|
Hi Everyone,
I am new to C++/CLI. I am trying to write a CLI wrapper on top of native C++ class.
I am a bit confused on how to marshal below mentioned C++ object to c++/CLI. Could you give me some ideas?
Native C++ Classes
class HeaderMessage {
double timestamp;
string ric_code;
}
class TradeMessage {
double price;
int size;
}
class RFARecord
{
public:
RFARecord();
HeaderMessage * hMsg;
list<TradeMessage *> qMsgs;
};
My C++/CLI classes look like this
public ref class RFARecordRef
{
public:
RFARecordRef();
RFARecordRef(RFARecord *record);
HeaderMessageRef hMsg;
List<TradeMessageRef> tMsgs;
private:
RFARecord *record;
};
ref class HeaderMessageRef
{
private:
HeaderMessage *hMsg;
public:
HeaderMessageRef(void);
};
ref class TradeMessageRef
{
private:
TradeMessage *tMsg;
public:
TradeMessageRef(void);
};
I am not sure if my approach is correct.
I read data from a text file and transfer this data in the form of RFARecords to my C# program.
What is the right way to wrap or marshal above data objects to C++/CLI which can then be consumed by my C# program.
Thanks in advance.
Regards, Alok
|
|
|
|
|
I have a headerfile for my strings and variables to use with my whole project. But I don't know, how to define or declare the similar for images...Iam facing the problem like the below...
For Strings....Below is good
#define MY_STR "My Value"
public:
System::Drawing::Image^ MyMainImge=System::Drawing::Image::FromFile("C:\\MyPrgCodes\\Images\\MyMenuImage.jpg");
error C3145: 'MyMainImge' : global or static variable may not have managed type
Any Ideas for me? Thanks
|
|
|
|
|
You are trying to declare and implement a variable without any context for it to exist within. Firstly the declaration needs to be inside a class, and secondly the implementation needs to be inside a constructor or other class function.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Thanks Richard![Rose | [Rose]](https://codeproject.global.ssl.fastly.net/script/Forums/Images/rose.gif)
|
|
|
|
|
I’m creating a window’s form application that will have a series of “do it” buttons and a large scrollable text area for feedback.
The feedback might be something like:
Item 1 completed
Item 2 completed
Warning: I had problems
Item 3 completed
Error: That was a serious problem
Item 4 failed
Item 5 completed
During the feedback I’d want to highlight words like Warning and Error so they pop out.
I tried using a RichTextBox, but it really only allows one selection at a time. I can highlight “Warning” on the fly, but when I try to then highlight “error” I change the selected area and “Warning” goes back to standard text.
My thought was to create a WebBrowser object instead of a RichTextBox object, then format it with HTML. But I can’t seem to find the right syntax to create the browser object, not give it a URL, then be able to build the HTML code on the fly from within my program.
Anyone know of the proper way to create a scrollable text box where I can format the text on the fly as my process runs?
|
|
|
|
|
There are many ways to achieve something like that, from simple to very complex:
1.
use a ListBox in OwnerDrawn mode; that will easily allow you to have a homogeneous style for each line of text, meaning you could simply have a line in red, or in a bold font, or ... . An example can be found here[^].
2.
Use a RichTextBox, and make sure to use it correctly. Which means:
- add text, select text, set properties for selected text, unselect;
- rinse and repeat.
3.
Use a WebBrowser; build an HTML document in memory, and assign it to the browser's DocumentText property.
4.
Create your own control, from scratch (based on UserControl or, my preference, Panel); paint everything yourself, and teach it any trick you want.
|
|
|
|
|
1. many times I want words in the line to be different, not entire lines.
2. I've looked for ways to "unselect" and the only thing I've found is to select from the end, size 0.
The problem I get is ever time I select a new area to highlight, it un-highlights the previous area.
3. I've tried the WebBrowser approach, it is the most promising. I can create anythign I like with it.
I used the WebBrowser->Document->Write( HtmlCode ) to add lines to the control and all is great -- almost.
My problem is I can't find a way to clear the control for the next "do it" run of the process.
It just keeps appending to the end of what is alreay there.
4. This might be my only answer, but I'd like to avoid it.
|
|
|
|