|
See don't consider a case of virtual function and inheritance in this case. I just want a clean idea what is happening behind the scene.
|
|
|
|
|
What you've basically got here is something that is essentially the same as the following: (note this is not inheritance, but aggregation --- done to illustrate a point)
struct Derived
{
Base1 b1;
Base2 b2;
}
void main()
{
Derived D;
Base1* bptr1 = &D.b1;
Base2* bptr2 = &D.b2;
}
The reason (Base1*)&D != (Base2*)&D is that each base class has to occupy some part of derived class Derived. In other words, Derived is composed of Base1 and Base2, so when you get a pointer to each of the base classes, it will point at the part of D that is that base class. Try switching the order of the base classes, you will see that the pointer values switch. That will illustrate that pointers to each of the base classes point to the part of Derived that is made up by the respective base class.
|
|
|
|
|
A very good explanation.
"After all it's just text at the end of the day. - Colin Davies
"For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus
|
|
|
|
|
hi
...posted a question yesterday concerning a problem with "MessageBox"
Now I know where the problem is, but I don´t know how to solve it.
Making a Windows Form App with VC++ .Net 2003, I add my own header file to the project. Trying to use MessageBox::Show("String") gives me an errormessage but only as long as the header file windows.h is included in the project.
Is this windows.h header file incompatible with VC++ or is there any tricks I have to know?
doneirik
|
|
|
|
|
Please write following details:
1) Which type of application u haev created ? (MFC/SDK)
2) what error studio flashes?
|
|
|
|
|
The Windows headers declare two versions of most APIs that take string parameters or buffers which contain strings. These typically end in either W, for a version taking Unicode (word-oriented) strings, or A, for a version taking ANSI (byte-oriented) strings. Windows 9x, in the main, only supplies the ANSI versions; Windows NT and successors (2000, XP, 2003) supply both versions. So there are actually two functions in the API: MessageBoxA and MessageBoxW .
For convenience the headers define a macro which, depending on whether UNICODE is defined, maps to the W or A version of the API. This allows Unicode and ANSI versions of the software to be compiled from the same sources just by defining or not defining UNICODE . So MessageBox is a macro defined to either MessageBoxW or MessageBoxA - the former if UNICODE is defined and the latter if not.
The C++ macro processor is dumb. It doesn't understand that you're trying to call the Windows Forms MessageBox class's Show method. It just replaces the text with either MessageBoxW or MessageBoxA . This will give a compile error because there's no class with that name.
I think the best thing for you to do is to isolate the .NET code in one set of source files, and the unmanaged code in another set. In the unmanaged set, include windows.h ; in the managed files, don't. If it's in your precompiled header file, remove it.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Hi there,
Come on, is it really possible that there isn't some one out there that knows how to solve my property problem ?
My problem, has I've already stated is that I need to do this in an ActiveX Control.
MyClass is a COleControl
MyClass2 is CWnd derived and supports OleAutomation
All I want to do is have a property of MyClass point to MyClass2, that way any property and methods exposed by MyClass2 will be available has MyClass.SomeProperty.MyClass2PropertyOrMethod .
Come on, please, someone, anyone, I am running out of time and haven't been able to get this to work.
Thanks for any help.
----------------
Lord Phoenix
----------------
|
|
|
|
|
Hi,
even though I am not quite sure of what you really want to do, I try to give you a solution to what I "think" you want.
Make a "long" property, through which you can pass an object address to your ActiveX control.
Inside there (assuming you have included the header file describing your object to be refered) make a type cast and you have the pointer to your object.
SkyWalker
|
|
|
|
|
You're right, not exactly what I wanted, but it might actually work, haven't tried that yet.
Do you know the Treeview control ? You can type TreeView1.Nodes.Count which will return the number of existing nodes.
Although this really has nothing to do with it, the concept is the same.
I want whoever is using my control to access both the Control Class (MyClass) and a few other internal classes (MyClass2) in the same manner.
Using the TreeView example, MyControl is the TreeView, Nodes is the property which if it ever works will map (MyClass2) and Count is some property or method of MyClass2.
Hope this clarifies it. In a COM this is reasonably easy to achieve, but it seams I can't get it to work with an OCX.
Thanks for your help, if you think of anything else please do share.
Best regards,
----------------
Lord Phoenix
----------------
|
|
|
|
|
there are 2 ideas which can access an active control by another (activeX or normal app etc).
1. use pointer directly
2. use LoadLibraryEx() function
i can not remember actual code, u can find many samples on VC CD disk.
good luck
includeh10
|
|
|
|
|
Please see my reply to Mircea.
Thanks for your help and do feel free to share any other thoughts you feel might help.
Best regards,
----------------
Lord Phoenix
----------------
|
|
|
|
|
Hi I'm planning a project where i'll use the MDI framework to describe a
factory floor/procudtion line. All the data from the Procudtion will be
recieved via UDP. I want my Document to contain all the data about the
production etc.
Now to my question: what would be the "correct" way to implement this
functionallity into the Doc/View arcitecture.
Give the Document a Thread that will pull data from the UDP,
store it and the notify the views.
or is there another way to gather data from the UDP that is better?
|
|
|
|
|
tom.schultz wrote:
Give the Document a Thread that will pull data from the UDP,
store it and the notify the views.
Sounds reasonable to me. Just beware if you haven't done any multi-threading before it can get pretty tricky, even more so with MFC.
Neville Franks, Author of ED for Windows www.getsoft.com and Surfulater www.surfulater.com "Save what you Surf"
|
|
|
|
|
I was reading up a bit on MSDN and they did not recommend using multi-threading and document view together.
But what do they know
I found a small test/case on the net. Documents and Timers, where they use a CWnd derviced class in the
document to recieve the timer event. That would also be a way to do this. That is: creating a class to
handle the rec/send events and just relay any data to the document.
BTW: Thanks for the input. I was a bit uncertain about my approach cause all info i found was based on
the fact that the view should be the only one to change the documents data. Not the document itself
Regards
Tom.Schultz
|
|
|
|
|
tom.schultz wrote:
I found a small test/case on the net. Documents and Timers, where they use a CWnd derviced class in the
document to recieve the timer event. That would also be a way to do this. That is: creating a class to
handle the rec/send events and just relay any data to the document.
I don't like the sound of that, in particular using CWnds with CDocument.
I use multi-threading quite heavilly in ED (see sig). In the Document I use a thread to read the file so the user can start viewing or editing large files straight away, without having to wait for the entire file to load. I also use threads for operations like find and find and replace which work at the document level.
Simply put it comes down too synchronization, and ensuring there aren't deadlocks. There are plenty of articles about this stuff around.
Surfulater (see sig) also uses threads in the Document to access its database.
Good luck.
Neville Franks, Author of ED for Windows www.getsoft.com and Surfulater www.surfulater.com "Save what you Surf"
|
|
|
|
|
Thank you. I'll have a look at those two programs and try to find more information before i proceede...
|
|
|
|
|
Can anyone let me know if the File, New(to create MDI Child windows) option in an MDI Application be disabled and the same functionality can be provided in a button click or some other event through code.
Thanx in advance
laiju
|
|
|
|
|
I have a tree ctrl with nodes having icons of different colours..
I have to set the background colour of text of each node with the same colour of the icon of that node. Pls help me to do this...
thnks in advance...
|
|
|
|
|
1. Derive your own class from CTreeCtrl
2. In CYourTreeCtrl::OnPaint()
- CPaintDC dc(this)
- create a compatible dc
- create a compatible bitmap and select it into the dc
- set clip region to be same as that in paint DC
- let the control do its default drawing by calling
CWnd::DefWindowProc( WM_PAINT, (WPARAM)yourMemDC.m_hDC, 0 )
- go through all the items in the tree and do what ever you need
(SetTextColor(), SetBkColor(), TextOut() in yourMemDC)
- at the end, BitBlt yourMemDC to the dc
- do not forget to free the resources )
SkyWalker
|
|
|
|
|
Hello everybody,
I have a problem with my last application.
I need to make a call to an external command line sw to elaborate a file and then process the same elaborated file.
I use this code:
exec_line.Format("app.exe %s %s", path_input, path_output);
UINT xxx = WinExec(exec_line, SW_HIDE);
if(fp = fopen(path_output,"rb"))
When I debug the app step by step everything works properly, but while executing in
runtime I get the error "...the memory could not be read..."
I thought the problem was that the fopen tries to access the file before it is "available"
on disk, so I used some patches like:
exec_line.Format("app.exe %s %s", path_input, path_output);
UINT xxx = WinExec(exec_line, SW_HIDE);
Sleep(200);
if(fp = fopen(path_output,"rb"))
or:
exec_line.Format("app.exe %s %s", path_input, path_output);
UINT xxx = WinExec(exec_line, SW_HIDE);
MessageBox("Dummy");
if(fp = fopen(path_output,"rb"))
but these are not clean solutions and do not work on all machines.
Do you know a method to solve this problem: I mean someway to "freeze" my aplication
until the command line has finished its tasks.
Thanks,
Marco.
|
|
|
|
|
My be my part of code can help you:
char * exec_line = "\"D:\\Programs\\Proba4\\Debug\\proba.exe\"";
STARTUPINFO si = { sizeof(STARTUPINFO) };
PROCESS_INFORMATION pi = {0};
BOOL bSuccess;
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
bSuccess = CreateProcess ( NULL, exec_line,
NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS,
NULL, NULL, &si, &pi );
WaitForSingleObject(pi.hProcess, 5000);
CloseHandle ( pi.hThread );
CloseHandle ( pi.hProcess );
|
|
|
|
|
Hello C++ ers,
Could anybody show me what should i refer/read before making an application
like adobe acrobat ? I think i will make a simple one.
It can be used to preview our print output (of course, multiple pages are also supported)
and we can also edit the text inside it (whatever text or image or any object).
Where can I start from ?
Regards,
Henky
12345
|
|
|
|
|
Why not have the "new" operator return a typed handle when you get memory on the heap (if you want it to)? And then use a "lock" operator to get a pointer to the memory, and the pointer is only valid within the scope of the function. Then on idle time, all memory is unlocked and can be compacted.
I wonder if there is a way of doing this by overiding the global new and delete operators and somehow checking for handle types?
In any case I think it would be better if the compiler was in on the action.
For instance you could declare a handle:
char* # hString;
hString = new char[80];
char* pString = lock hString;
strcpy( pString, "A String");
int len = strlen( pString );
And when you want to free the memory:
delete [] hString;
And when calling a member function:
CThisObject* # hThis = new CThisObject( data );
if( hThis )
hThis->DoThat();
is the same as:
CThisObject* # hThis = new CThisObject( data );
if( hThis )
{
CThisObject* p = lock hThis;
p->DoThat();
}
In any case, I'm sure die-hard C++ programmers would prefer managed memory along these lines instead of all the crap you have to deal with in .NET managed C++.
|
|
|
|
|
I am using visual studio .net and want to save a BMP file to JPG format. How to do this? Is there a sample code for reference?
Thanks.
|
|
|
|
|
if it's really just the file you'd like to convert manually (not code) just do it in Paint, but I'm not sure you can load jpg into the resources.
No hurries, no worries.
|
|
|
|