|
I found my pure virtual function problem - the base abstract class cannot be instantiated, so IMPLEMENT_DYNCREATE and DECLARE_DYNCREATE pair ( MFC "standard" )need to be deleted.
Working with MFC is fun!
Next problem...
Hello Ash, sorry to bug you , but I told you I am a greenie in using inheritance.
My learning process is not starting well.
I am not sure if it is me or VC 6.0 wizard, but I cannot get the pure virtual function defined using wizard or manually.
Maybe I am missing some setting in compiler commands?
I a have never used virtual options in the wizards.
Here is the compiler error:
Z:\0\0 MDI\V1\TCC_MDIView_Base.cpp(17) : error C2259: 'CTCC_MDIView_Base' : cannot instantiate abstract class due to following members:
z:\0\0 mdi\v1\tcc_mdiview_base.h(13) : see declaration of 'CTCC_MDIView_Base'
Z:\0\0 MDI\V1\TCC_MDIView_Base.cpp(17) : warning C4259: 'void __thiscall CTCC_MDIView_Base::Test(void)' : pure virtual function was not defined
z:\0\0 mdi\v1\tcc_mdiview_base.h(24) : see declaration of 'Test'
Z:\0\0 MDI\V1\TCC_MDIView_Base.cpp(17) : error C2259: 'CTCC_MDIView_Base' : cannot instantiate abstract class due to following members:
z:\0\0 mdi\v1\tcc_mdiview_base.h(13) : see declaration of 'CTCC_MDIView_Base'
Z:\0\0 MDI\V1\TCC_MDIView_Base.cpp(17) : warning C4259: 'void __thiscall CTCC_MDIView_Base::Test(void)' : pure virtual function was not defined
z:\0\0 mdi\v1\tcc_mdiview_base.h(24) : see declaration of 'Test'
Here is the base calls declartion:
virtual void Test() = 0;
The VC++ 6.0 wizard does not generate the definition. I undestand pure virtual does not need it, but the compiler complains about it, twice! I understand I could define it in base class, but even than I get same warnings / errors.
Here is the definition in the derived class and there are no errors from compiler.
void CTCC_MDIView_Base_Preview::Test()
{
}
I also do not get why there are warnings and errors.
Both "problems" should be errors. But that is my opinion.
Again, thanks for your help and time.
Vaclav
-- modified 24-May-12 23:14pm.
|
|
|
|
|
Hi!
Is it possible to deallocate a memory that was allocated by new using free function? Otherwise what will happen if we deallocate using free function while the memory is allocated using new in C++?
|
|
|
|
|
See here[^].
Veni, vidi, vici.
|
|
|
|
|
Thank you Sir .
|
|
|
|
|
You are welcome.
Veni, vidi, vici.
|
|
|
|
|
|
I have a Delphi application which Creates a shared memory uses CreateFileMapping, OpenFileMapping, MapViewOfFile functions.
Now I wanted to share the same memory for my MFC application. I used the OpenFileMapping, MapViewOfFile functions.
I created a structure exactly same in size as the Delphi application and mapped the structure object.
sample code:
HANDLE hMapObject2;
hMapObject2 = OpenFileMapping( FILE_MAP_ALL_ACCESS, FALSE, "PP101U3_SHARED");
if( !hMapObject2 )
{
AfxMessageBox("Failed to open Simpack DataBase");
return( 0 );
}
Simpack = ( struct SIMPACKDB *) MapViewOfFile( hMapObject2, FILE_MAP_ALL_ACCESS, 0, 0, 0 );
if( !Simpack )
{
AfxMessageBox("Failed to create Simpack File Map View");
return(0);
}
Esim->SPV1 = Simpack->SP_Z;
I am able to read the values exactly correct for all the member variables in the structure.
But when I try to write value in the shared memory, its not changing. It shows the previous value immediately.
The value of Simpack->SP_Z[15] is 0.5010 as read
from the shared memory which is set by the Delphi application.
When I set or write the value of the same variable to the shared memory using the code:
Simpack->SP_Z[15] = 0.6123;it still shows the previous value 0.5010. When I change the same variables value in the Delphi application it changes and the changed value can be read here in the MFC application.
Please help me how to write the values in the shared memory. Is there anything wrong in the code?
|
|
|
|
|
manoharbalu wrote: When I set or write the value of the same variable to the shared memory using the code:
Simpack->SP_Z[15] = 0.6123;it still shows the previous value 0.5010.
What does 'it still shows' mean? You checking it in debugger or printing the values.
I suggest you to check whether that process has write permission for that shared memory.
|
|
|
|
|
The previous value 0.5010 is the orginal value of the same variable in the Delphi application. Also it is the value in the MFC application that is got after mapping it to the shared memory using OpenFileMapping and MapFileView functions.
This value is seen in the watch window of the Debugger in the MFC application
|
|
|
|
|
|
Richard MacCutchan wrote: Why have you reposted this question[^]?
Probably because he wasn't able to get an urgentz answer from the first posting.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi all,
I am having a problem. I am having two threads, one thread i doing some work inside a for loop and inside that for loop its making a call for second thread.
My problem is that my first thread should not resume its working untill thread2 finishes it work, and after thread2 has finished its work it should start its working after thread2 was called.
Can i use CEvent for this???
I am not getting how to do it.
Thanks in advance
|
|
|
|
|
Have a look at this[^] for basic usage of event object. You can use the same logic to use CEvent on you own.
You may find this[^] code project article useful too.
|
|
|
|
|
Sounds like a good time to use WaitForSingleObject() in the first thread, waiting for an event or some other object to get notified/released/set in the second thread.
==============================
Nothing to say.
|
|
|
|
|
VCProgrammer wrote: my first thread should not resume its working untill thread2 finishes it work
So why are you using threads? This is serial processing not parallel, so using threads does not provide any advantage.
Programming is work, it isn't finger painting. Luc Pattyn
|
|
|
|
|
VCProgrammer wrote: Can i use CEvent for this???
yes you can! however am agree with richard!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
I have a Delphi application which Creates a shared memory uses CreateFileMapping, OpenFileMapping, MapViewOfFile functions.
Now I wanted to share the same memory for my MFC application. I used the OpenFileMapping, MapViewOfFile functions.
I created a structure exactly same in size as the Delphi application and mapped the structure object.
sample code:
HANDLE hMapObject2;
hMapObject2 = OpenFileMapping( FILE_MAP_ALL_ACCESS, FALSE, "PP101U3_SHARED");
if( !hMapObject2 )
{
AfxMessageBox("Failed to open Simpack DataBase");
return( 0 );
}
Simpack = ( struct SIMPACKDB *) MapViewOfFile( hMapObject2, FILE_MAP_ALL_ACCESS, 0, 0, 0 );
if( !Simpack )
{
AfxMessageBox("Failed to create Simpack File Map View");
return(0);
}
Esim->SPV1 = Simpack->SP_Z;
I am able to read the values exactly correct for all the member variables in the structure.
But when I try to write value in the shared memory, its not changing. It shows the previous value immediately.
The value of Simpack->SP_Z[15] is 0.5010 as read
from the shared memory which is set by the Delphi application.
When I set or write the value of the same variable to the shared memory using the code:
Simpack->SP_Z[15] = 0.6123;it still shows the previous value 0.5010. When I change the same variables value in the Delphi application it changes and the changed value can be read here in the MFC application.
Please help me how to write the values in the shared memory. Is there anything wrong in the code?
|
|
|
|
|
Please put your code between <pre> tags to make it easy to read.
What data type is the Simpack->SP_Z array?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
My Code:
hMapObject2 = OpenFileMapping( FILE_MAP_ALL_ACCESS, FALSE, "PP101U3_SHARED");
if( !hMapObject2 )
{
AfxMessageBox("Failed to open Simpack DataBase");
return( 0 );
}
Simpack = ( struct SIMPACKDB *) MapViewOfFile( hMapObject2, FILE_MAP_ALL_ACCESS, 0, 0, 0 );
if( !Simpack )
{
AfxMessageBox("Failed to create Simpack File Map View");
return(0);
}
Simpack->SP_Z = 0.6212;
The member sp_z is of type float
|
|
|
|
|
Are you getting any Access violations when you try to set the value in the MFC program?
You might want to use the VirtualQuery function to investigate if the view you have mapped is as you expect.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I think it would have been mapped because I am able to read the values from the delphi application which is creating the shared memory. And the values are also updated in the MFC application when the value is changed in the Delphi application.
I checked till the last member variable in the entire structure.
|
|
|
|
|
I know, but I suggested using VirtualQuery because there might be something unusual about the access permissions on the pages of memory in the mapping.
Can you show the code that creates the file mapping?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Delphi Code:
while not bDone do begin
s_hMemFile := CreateFileMapping( $FFFFFFFF, Nil, PAGE_READWRITE,
0, cbSize, @sTemp[1] );
idErr := GetLastError;
if ( idErr <> 0 ) and { => Function Failed }
( idErr <> ERROR_ALREADY_EXISTS ) then begin
CloseHandle( s_hMemFile );
s_hMemFile := 0;
inc( iRetryCount );
// Map the File to Memory
if bDone or not FGenerateName then
Data := MapViewOfFile( s_hMemFile, FILE_MAP_ALL_ACCESS, 0, 0, ENTIRE_FILE )
else begin
if FGenerateName and (Data <> Nil) then begin
try
UnMapViewOfFile( Data );
finally
Data := Nil;
end; { try }
end; { if }
end; { if then else }
|
|
|
|
|
I don't see a problem there, however, I have to ask about the code you use to set the value(s) in the MFC program.
In your first post you showed SP_Z being used with an index, such as SP_Z[15] , and in the next post, you showed that you're setting it without an index. Is this an array or not an array?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I am sorry. The first one is correct. Its an array.
|
|
|
|