|
Hi all
I have an MFC class named CCoordWnd derived from CWnd. Now I'm porting this
class to .Net.So,I started with deriving from class
System::Windows::Forms::UserControl.
My MFC class CCoordWnd have overloaded constructors like these.
CCoordWnd(unsigned int cnum,CCoordWnd **myptr);
CCoordWnd(CCoordInterface *cip,CCoordWnd **myptr);
CCoordWnd(CCoordInterface *cip,unsigned int cnum,CCoordWnd **myptr);
and a member variable like this.
CCoordWnd ** m_myptr
Can anybody help me how can I implement these functionality in ManagedC++ environment.This is very urgent work for me.Please help me.
Thanks in Advance
Regards
Krishna
|
|
|
|
|
Here's the problem I'm facing: I have a hierarchy of classes:
class button;
class bitmap_button : public button;
class text_button : public button;
Now I want to wrap this is managed c++. How should I do this ?
Jonathan de Halleux.
|
|
|
|
|
Probably something like:
class __gc managed_button {button* bt_;...};
class __gc managed_bmp_button : public managed_button {bitmap_button* bmpBt_;...};
|
|
|
|
|
|
Is it possible to use a form written in C# in my MC++ app? I don't want to have to create the form programaticaly because it has quite a few controls on it. I added a Windows Form project to my solution and created the form, but I've no idea how I reference it in my MC++ app. I tried simply using Namespace::Classname , but that failed. Would I have to compile the form into a dll so I can reference it? If so how would I do that?
Thanks for the help.
- monrobot13
|
|
|
|
|
It would have to reside in a dll. You would just compile it as you would a normal dll. You could either reference it with a project reference, or with a reference to the dll binary.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
Thanks for the reply. I acutally did get it working compiling it as a dll, but I have another question now. In order for it to work I have to copy the dll to the same directory that my exe excutes in. This is a royal pain and I know it's the wrong way to do it. I want to know how I can get the exe to use the dll from the location the dll is build to or how I can automatically have VS.NET copy the dll to the exe directory when it's built.
Thanks again.
- monrobot13
|
|
|
|
|
Well, I don't know about VS.NET, but I use SharpDevelop, and it allows you to specify scripts to run before and after a build.
Another thing you could do is to change the output directory to either the same directory as the exe, or a subdirectory under the exe directory, named the same name as the dll (w/o the ".dll" part).
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
I'll see what I can do. Thanks for the help.
- monrobot13
|
|
|
|
|
I'm new to this myself, but isn't that what the
#using <drive:\path\filename.dll>
syntax is for?
|
|
|
|
|
In the VS.NET environemnt, right click your project and select "Properties", this will bring up the property dialog for that project.
Expand the "Build Events" leaf, and then select the "Post-Build Event" item.
In the Command Line box, enter something along the lines of:
copy "$(TargetPath)" ..\bin\debug\
Where ..\bin\debug (just taken from one of my projects) is the fully-qualified or relative path to where you want the file to be copied after successful compilation/linking. Note that in my example, I have separate output directories for debug/release builds and so copy to different directories. You may just have one directory for both configurations, and if so should select "All configurations" from the "Configuration" drop-down prior to entering the line above.
Hope that helps.
Ben
--
When it comes to maths and me, the wheel's going but the hamster's dead.
|
|
|
|
|
Thanks for help. I figured it out after about 10 minutes or so of fumbling around in the properties.
- monrobot13
|
|
|
|
|
I've almost completed my first custom control, however I can't find out how to modify the vairables at design time by appearing in the Properties dialog in form view.
Could anyone tell me how to do it?
Thanks
|
|
|
|
|
Which of the following takes more CPU cycles?
(a) if(i==j)
(b) i*j
Thanks!
norm
|
|
|
|
|
|
With new processors, pentium or better, this is not a question with an exact answer. The answer both may take 1 cpu clock or as many as the length of the integer pipeline - 2 instructions on the cpu. For Athlons this maximum is 10 clocks. For P4 cpus this maximum is 18 clocks. Each integer instruction has to go through the entire pipeline but if there is no register or memory dependence the next instruction will be started on the next cpu cycle. On p4 this will be 1/2 a clock because the p4 alu runs its pipes 1/2 a clock apart so in effect it runs them at 2 * the cpu frequency. A branch misprediction on either procesor will cause the entire pipeline to have to be emptied so in effect the next instruction may have to wait as long as the length of the pipeline - 2 instuctions.
[EDIT]
Now to answer the original question. If either I or J are random than B is always faster. If the answer (i==j) is false or true over 90% than A is probably faster unless J*I has no register dependence on the next or previous calculation. If this is the case B is always faster.
[/EDIT]
John
|
|
|
|
|
Assuming the compiler uses the same method to access i and j in both cases:
(a) compiles into a compare (a subtraction) and a conditional jump instruction.
(b) compiles into a multiplication instruction.
Depending on the processor and the values of i and j , (a) may actually take more CPU cycles.
Software Zen: delete this;
|
|
|
|
|
Destructors won't execute until an object is deleted -- which may not happen for a while in managed projects. Is there any function you can write to have called immediately when the last reference to an object is removed?
Thanks
READIN writin rhythmetic
|
|
|
|
|
Jeremy Osner wrote:
Is there any function you can write to have called immediately when the last reference to an object is removed?
No.
You can manually force the destructor to be called by explicitly calling the delete operator on the reference object. However, while the destructor method will execute (which may be enough in certain cases where your main concern is performing clean-up chores), the memory allocated for the object will not actually be freed till the next garbage collection cycle.
Cheers,
Tom Archer
Inside C#, Extending MFC Applications with the .NET Framework
It's better to listen to others than to speak, because I already know what I'm going to say anyway. - friend of Jörgen Sigvardsson
|
|
|
|
|
There is no such thing as C++ destructors, but you can wrap a __gc class into a __nogc one that can implement reference counting for you.
|
|
|
|
|
Nemanja Trifunovic wrote:
There is no such thing as C++ destructors
I'm assuming you mean that there are no destructors in managed classes since we've used destructors in native classes for years. Even then, yes, there are destructors in managed C++ and as I noted in my reply to the original post you can explicitly call them.
Cheers,
Tom Archer
Inside C#, Extending MFC Applications with the .NET Framework
It's better to listen to others than to speak, because I already know what I'm going to say anyway. - friend of Jörgen Sigvardsson
|
|
|
|
|
Yes, wrong wording, sorry. What I meant is that we don't have destructors in __gc classes. We only have functions that look like destructors, but they are really finalizers, not real destructors.
|
|
|
|
|
True. However, even then we're talking a really fine line of differentiation as C++ .NET reference object destructors are invoked when the object is deallocated and can be manually invoked via the C++ delete operator.
Krista
"Who doesn't bend before the wind is mighty apt to break."
Author Unknown
|
|
|
|
|
Hi all
I'm trying to use a UnmanagedC++ class in my MC++ application.The unmanaged class internally using CString class as member variables.I'm converting the String to LPCTSTR and passing it as a parameter to the methods of the unmanaged class.There i'm getting access voilations on CString class GetData()method(this is inside the class CString).Can anybody help me how to solve this problem and what are all the other settings needed.(in project options i have enbaled using MFC in dynamic libraries).
Thanks You
Rgds
Krishna
|
|
|
|
|
Are you making sure to pin the String object's memory so that the GC doesn't move it once you've converted it? For example, the following code would convert a String to a __wchar_t type (note the pin keyword).
<br />
#include <vcclr.h><br />
String* s = S"Hello";<br />
const __wchar_t __pin * str = PtrToStringChars(s);<br />
Cheers,
Tom Archer
Inside C#, Extending MFC Applications with the .NET Framework
It's better to listen to others than to speak, because I already know what I'm going to say anyway. - friend of Jörgen Sigvardsson
|
|
|
|