|
I'm playing with this for first time. Anyhoot.. in the output its telling me that the leak occured in crtdbg.h instead of Test.h. Is this normal behavior?
<br />
#define _CRTDBG_MAP_ALLOC<br />
#include <stdlib.h><br />
#include <crtdbg.h><br />
<br />
#include "Test.h"
<br />
int main()<br />
{<br />
_CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE );<br />
_CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDOUT );<br />
_CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE );<br />
_CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDOUT );<br />
_CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE );<br />
_CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDOUT );<br />
<br />
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );<br />
<br />
<br />
<br />
<br />
<br />
_ASSERT(false);
<br />
int * leakyInt = new int;
<br />
Test test;
<br />
return 0;<br />
}<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
|
|
|
|
|
This is the C++/CLI forum. You should post your question in the MFC/Visual C++ forum to receiver your request answer.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
What if you add this (in your Test.h)
#ifndef TEST
#define TEST
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
class Test
{
...
|
|
|
|
|
yep that works. had to include another header in main.cpp to get that DEBUG_NEW thing.
<br />
#ifdef _DEBUG<br />
#define _AFXDLL<br />
#include <afx.h><br />
#define new DEBUG_NEW<br />
#endif<br />
|
|
|
|
|
Hi guys,
I think I need some serious painkillers on this!
Short version:
Can anybody explain in details how to expose a C# WinForms Control as ActiveX control. Either via hosting it in a MFC ActiveX control or by implementing it completely in C# (implementing all interfaces, registration/unregistration stuff, events).
Perhaps somebody has a template project for this problem where I just can drop in my Windows Forms Control and is willing to share it with me and the others (sounds like XMas, I know).
Bloody details:
We have a large client application with lots of legacy code that implements an ActiveX container. So you can add e.g. GUI components by providing new ActiveX controls. Since we have almost year 2007 we want to develop new GUI components with Windows Forms instead of the existing MFC/OWL stuff (yes! OWL! ). We recently migrated to Visual Studio 2005 (.NET 2.0).
As far as I can see there are 2 main approaches:
(Approach 1) Use of a MFC ActiveX control for hosting the Windows Forms control and use the new MFC 8.0 template classes CWinFormsDialog[^] or CWinFormsView[^] for adding the WinForms control to a CDialog/CView.
(Approach 2) Implement all necessary COM interfaces completely in C# and make them visible to COM and do the extra COM registration/unregistration stuff as explained here[^]. So the resulting component would be completely written in C# with no other languages involved. Furthermore we have about half a dozen COM interfaces for communication between the client and the ActiveX component. These interfaces must be implemented too. Sounds like very much more work than approach one.
So we decided to follow approach one - hosting a WinForms control within a MFC ActiveX control. What a pain until now!
This is what we did (following the MSDN examples[^]):
(1) Created an "empty" MFC ActiveX control, with all of our COM interfaces, showing an empty CDialog. Works flawlessly when added to the client application or to the ActiveX Control Test Container.
(2) Enabled Common Language Runtime Support (/clr) for the project. After fixing some compiler warnings the project compiles fine to MSIL.
( #1) Here is already the first major problem: When the project is started after '/clr' is activated, Visual Studio 2005 locks up completely while loading the CLR DLLs (e.g. 'mscoree.dll', 'mscorwks.dll'). There is no error message or crash, but VS2005 hangs infinitely and the only thing to do is killing the 'devenv.exe' process. Why is this? But it's possible to start the application regularly! Only when started via VS2005 it hangs. The ActiveX still shows up correctly when the application is not launched via VS2005.
(3) Since I found no solution for this problem I sighed and added a CWinFormsControl member to the "empty" CDialog as described in the MSDN example here[^] (which works by the way perfectly when used in a stand alone dialog application). I tried two variants:
CWinFormsControl<WinFormsCtrl::UserControl1> m_WinFormsCtrl;
CWinFormsControl<System::Windows::Forms::LinkLabel> m_WinFormsCtrl; The result was the same in both cases:
( #2) When the ActiveX is about to be displayed it crashes in 'CWinFormsControl<TManagedControl>::InternalCreateManagedControl' (<VS2005-install-path>\vc\atlmfc\include\afxwinforms.inl). Output window says: A first chance exception of type 'System.AccessViolationException' occurred in <MyActiveX>.OCX
I got this information by attaching to the application process with VS2005 when the application is already running.
I read several threads where members of the Visual Studio Team and MVP's are saying that MFC 7.1/8.0 are officially supported unmanaged hosts for Windows Forms controls, just like Internet Explorer. But it seems not to apply for MFC ActiveX controls!?
cheers,
mykel
If they give you lined paper, write the other way!
|
|
|
|
|
C'mon... doesn't anybody have experience with hosting WinForms controls inside MFC ActiveX controls?
There must be lots of large "legacy" applications out there which implement an ActiveX container for (GUI) extensions.
Any help is appreciated, even comments like "Careful, you'll likely get burned using this approach, because ..."
cheers,
mykel
If they give you lined paper, write the other way!
|
|
|
|
|
I woud like an example to override,
ListView::set_DoubleBuffered() (Currently is Protected)
Thanks in advance
ps: I had already look on CP, but found nothing.
|
|
|
|
|
This is how you override a property:
ref class MyListView : ListView
{
public:
protected:
virtual property bool DoubleBuffered
{
bool get () override
{
return ListView::DoubleBuffered;
}
void set (bool value) override
{
ListView::DoubleBuffered = value;
}
}
private:
};
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
|
How can i limit my app to one instance?
|
|
|
|
|
Search for "single instance" or "one instance" on this site. You will get lots of results.
|
|
|
|
|
Thanks, Found with mutex method.
ps: I did search, but with wrong keywords
|
|
|
|
|
hi,
i would like to hide(or rather, to have the form disappear) after a new form has been created after clicking on "new" in the menustrip.
please help!
my codes thus far:
private: System::Void newToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e)
{
Form1^ newForm = gcnew Form1();
newForm->ShowDialog();
|
|
|
|
|
mactick wrote: i would like to hide(or rather, to have the form disappear) after a new form has been created after clicking on "new" in the menustrip.
Prety easy:
mactick wrote: Form1^ newForm = gcnew Form1();
this->Visible = false; // Hide current form
newForm->ShowDialog();
this->Visible = true; // show current form
|
|
|
|
|
if i wish to close the old form instead of hiding it after a new one has been created, how do i do that? 
|
|
|
|
|
Form1^ newForm = gcnew Form1();
newForm->Show(); //ShowDialog is opening modal window, It won't contiune execution Unless it isn't modal.
this->Close();
|
|
|
|
|
|
Hi all,
I have a form called: Form1 (Form1.h) and another form called: add_key_Value (add_key_Value.h)
Now I want to show the form add_key_Value:
So I include the header file add_key_Value.h in the Form1.h
And perform the following code:
add_Key_Value^ form2 = gcnew add_key_Value;
form2->Show();
Now in the add_key_value form I want to access the members of Form1:
So I include the header file Form1.h in the add_key_Value.h
And perform the following code: (ERRORS)
Form1^ mainform = gcnew Form1;
mainform->edtTextBox->Text = "Just testing";
Errors:
Error 3 error C2065: 'Form1' : undeclared identifier c:\documents and settings\qx55246\my documents\visual studio 2005\projects\cnfedtctrl\cnfedtctrl\add_key_Value.h 231
Error 4 error C2065: 'mainform' : undeclared identifier c:\documents and settings\qx55246\my documents\visual studio 2005\projects\cnfedtctrl\cnfedtctrl\add_key_Value.h 231
Error 6 error C2227: left of '->edtTextBox' must point to class/struct/union/generic type c:\documents and settings\qx55246\my documents\visual studio 2005\projects\cnfedtctrl\cnfedtctrl\add_key_Value.h 232
Can anyone please help ???
Many Thanx
The only programmers that are better than C programmers are those who code in 1's and 0's.....
 Programm3r
|
|
|
|
|
You have a circular reference of header files
Form1.h includes add_key_value.h which includes Form1.h which includes add_key_value.h etc etc etc
Split your implementation into .h and .cpp files and use a forward declaration so you can use typename^ in the header file
Form1.h
#include "add_key_value.h"
...
add_Key_Value^ form2 = gcnew add_key_Value(this);
form2->Show();
add_key_value.h
class Form1;
public ref class add_key_value.....
{
public:
add_key_value(Form1^ mainForm);
private:
Form1^ mainForm;
}
add_key_value.cpp
#include "Form1.h"
add_key_value::add_key_value(Form1 ^ mainForm)
{
this.mainForm = mainForm;
}
System.IO.Path.IsPathRooted() does not behave as I would expect
|
|
|
|
|
|
You can't do it in that way.
in add_keyValue.h:
you have Form1 ^mainForm;
but to able to declare that, you have to use #Inlcude "Form1.h"
but in Form1.h you must have #include "add_keyValue.h". So you woud have compile error. If in theorey, compiler coud run to infinitive loop
|
|
|
|
|
|
First Thing, it shoud be:
add_Key_Value^ form2 = gcnew add_key_Value();
Form1^ mainform = gcnew Form1();
Second, you can't create a new instance of a parrent form. With an include, it coud get theoretical to infinitive loop.
Consider the folowing example:
core.h
#ifndef _CORE_H_
#define _CORE_H_
public ref class Core
{
public:
Core()
{
test = gcnew String("");
}
public: String ^test;
};
#endif //_CORE_H_
Form1.h
#include "core.h"
public: Core ^core;
core = gcnew Core();
add_Key_Value^ form2 = gcnew add_key_Value();
form2->core = this->core;
form2->Show();
MessageBox::Show(core->test);
add_key_Value.h
#include "core.h"
public: Core ^core;
core->test = "Just testing";
|
|
|
|
|
Thanx for the help.... I'll try it ....
The only programmers that are better than C programmers are those who code in 1's and 0's.....
 Programm3r
|
|
|
|
|
Hello,
I have a native MFC dll which I need to access from the C# application.
I have written a managed C++ wrapper for this dll.My wrapper is a class library project.
The native dll(MFC dll) basically opens a MFC CArchive serialized file and deserializes it.
My c# app needs to access the data in this MFC CArchive.
I pass the filename as parameter to the native Dll member function which should open it and deserialize it.
However,when ever I try to call this function from the C# app -> managed c++ wrapper,the "CFile.Open' fails.On the other hand,the same file is successfully opened when other MFC apps call this native dll.
I have checked if the filename(parameter for the Load function in the native dll) is correctly received in the native dll and it is correct.
Any suggestions/pointers on what the problem mite be would be really appreciated.
Thanks
Madhuchhanda
|
|
|
|