|
Hi, everyone,
Recently I am thinking of using one pointer to access two different class. I don't know how to do this.
Here is the detail description:
I've a document class CMyDoc with a view class CCView.
In CCView's OnDraw function, I want to use one pointer pDoc->pCurImage to draw a image (eg. pDoc->pCurImage->Draw()). Because the two image buffer class are similar. They both have a draw function(and a lot of other function except their data type are diferrent). When I load an image from a file, the color image will be loaded into the color buffer(m_ColorImage), and the gray scale image will be loaded into the B/W buffer(m_BWImage), then a pointer m_pCurImage will pointer to the correct image buffer for the view class to display it.
But since the pointer type is (void*), how can a view class to use it.
Or is there any other elegant way to do the same job?
class CMyDoc : public CDocument
{
protected: // create from serialization only
CMyDoc();
DECLARE_DYNCREATE(CMyDoc)
public:
CBWImage m_BWImage;
CColorImage m_ColorImage;
void* m_pCurImageBuf;
...
...
...
}
Is their anybody can help? Any comments are greatly appreciated!
Best Regards,
Wayne King,
17 May 2002
|
|
|
|
|
Inherit the two different classes from the same base class, and use virtual functions for the similar functions in the classes.
|
|
|
|
|
You can cast the void* to the pointer type you need.
Nish
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
Thanks for mark & nish's kind reply.
|
|
|
|
|
I'v almost finished my first VC++ App, which is great.
But I've still got a big problem, which is not great.
The application logs data from the RS232 port over long periods of time. It displays this data in a list box, on a graph and in a 'LCD Meter' (which I draw). All in a modeless dialog box.
The problem is that if I leave it running for several hours, then the PC gradually gets more and more 'sluggish'. First you notice the mouse not responding very well and it takes ages to redraw the window. I've noticed that the clock in the corner of the screen starts to read about 2 hours slow, but when you reboot it is OK. In the end the whole system is too unresponsive to do anything so you have to reboot. Its an MDI application, written on VC++6, I'm testing it on a Win98 macine.
I'm guessing that I'm either running out of memory due to a memory leak (but I can't find one) or could I have too many messages for the system to cope with?
I just don't know where to start on this one. Any advice?
Thanks.
Ali
|
|
|
|
|
Sounds like you could possibly have a resource leak. On Win98, you have a diagnostic program called the resource meter (RSRCMTR.EXE). Run that program at the same time as your program is running, and it will tell you what your resource usage is.
Resource leaks occur if you do not release or delete any GDI resources (pens, brushes, fonts, cursors, icons, or bitmaps) you may have created.
---
CPUA 0x5041
Sonork 100.11743 Chicken Little
Orgasms are universal!! -- Mike Mullikin in The Lounge 21:27 15 May '02
|
|
|
|
|
I've checked and checked my GDI resources, but it sounds like that is probably where the problem is, so I must be looking in the wrong place. I'll just have to look some more.
Thanks for the tip about the reasource meter, I'll go and look at that. It sounds really useful.
Thanks
Ali
|
|
|
|
|
Do you use GetDC() [or equivalents] at all?
I mistake I've made in the past was to have calls like this
SomeFunctionThatNeedsADC( GetDC() );
which allocates a DC, but never frees it, meaning you gradually run out of resources. The proper way is
CDC* pDC;
pDC = GetDC();
SomeFunctionThatNeedsADC( pDC );
ReleaseDC( pDC );
Also note that Windows2k/XP has much better resource handling to 9x so if you find your prog runs fine on 2k but gradually dies in 9x, then it probably is a resource problem
--
Help me! I'm turning into a grapefruit!
|
|
|
|
|
I think you can drop the idea of "too many messages". From your explanation it seems to be either memory (which is very easy to determine, I'm actually a bit surprised you haven't already done it) or some other resource(s) such as HANDLE's or some GDI (or even USER) objects.
Id start out by checking the graph and the LCD "meter" code to see if they aren't releasing something.
|
|
|
|
|
Thanks for the help, it sounds like a resurce problem. I've checked them over and over, but I must be missing something. I'll have another look.
Thanks
Ali
|
|
|
|
|
Another thought that struck me: Are you sending any messages from one control to another?
I've seen cases where, during handling of a window message, one control sends a message to another control when it instead should have posted it. This can lead to the second control creating another update message being sent from windows and...
Let's just say that the call stack can grow really deep.
|
|
|
|
|
Any body used boost library in VC++ ?? I am using it first time for exploring thread models but the VC++ compiler is giving Linker errors. It seems to me that Linker settings are not appropriate. If any one of you know the linker settings for boost library in VC++ 6.0 then please tell me. I've posted this problem in boost forums but no answer is arriving.
SattarA
|
|
|
|
|
I've used it a little bit. But I've only used the regex and lexical_cast stuff out of it, not the thread library. I have had no trouble using it in Visual C++ 6.0.
What sort of linker errors?
|
|
|
|
|
Is there any way to read Motorolla-style (Big Endian) file formats? The problem is that bytes ordering starts from high byte to low byte, unlike usual (for Windows) from low to high. E.g. if you will write DWORD type with value 1 into binary file using any file routines (MFC, API, whatever) you will see in the file such numbers: (in hex display)
01 00 00 00
When you'll read it, you will get you "1" back.
Now Motorolla style is vise versa:
00 00 00 01
I have such file (actually everyone has it - it is TrueType fonts) and I need to read the numbers in it correctly. Of course when I'm using CFile or file handle to read data, I get different numbers, since it reads it in Windows style
Any way to override it?
Philip Patrick
Web-site: www.stpworks.com
"Two beer or not two beer?" Shakesbeer
Need Web-based database administrator? You already have it!
|
|
|
|
|
We have done a lot of work rearranging bytes and words between big-endian and little-endian systems. Be careful, though, as usually the difference is not byte reversal, but word (i.e., 2-byte groups) reversal, depending on the processor. A fairly easy approach is to use a structure with high-word and low-word (or bytes, as needed). The read function can read file contents into the big-endian elements of the structure, and then a little-endian value can be constructed by combining those elements in reverse order.
Dave
"You can say that again." -- Dept. of Redundancy Dept.
|
|
|
|
|
Uff.. lol
Well, did it, but it is kinda dissapointing to reverse bytes and words for each member of structure
Imaging that I have like 5 structures (for now) and about 5 members in each (short or long). I'm rearranging the order for each member. What I thought, maybe there is some "flag" in functions like "CreateFile", etc., which will tell the system to read data in Big endian style. But didn't find nothing, so I guess this is the only way
Philip Patrick
Web-site: www.stpworks.com
"Two beer or not two beer?" Shakesbeer
Need Web-based database administrator? You already have it!
|
|
|
|
|
I agree, if only it were that easy. We run into this problem when reading data from external hardware devices. Many of those are made with an embedded chip and their available output has that chip's byte ordering. May or may not correspond to PCs and Windows, so we have to change it as needed. Unfortunately, I haven't ever seen that nice flag, but it sure would be useful.
Good luck,
Dave
"You can say that again." -- Dept. of Redundancy Dept.
|
|
|
|
|
I've defined the interfaces IRolesUsers and IRole (from IDispatch). They should be implemented by the following coclass:
coclass RolesUsers
{
[default] interface IRolesUsers;
interface IRole;
};
The problem is that in VB the interface IRolesUsers appears "RolesUsers" but
IRole comes with "IRole".
What should i do to make IRole be exposed "Role" or IRolesUsers to be "IRolesUsers"?
rechi
|
|
|
|
|
... connections from the clients in the LAN?
I can make my app listen to the LAN IP... is it the only way?
Rickard Andersson@Suza Computing
ICQ#: 50302279 (Add me!)
E-mail: nikado@pc.nu
I'm from the winter country SWEDEN!
|
|
|
|
|
Add an entry to your firewall to deny connections from other IPs to that particular port. If you don't have a firewall, I guess on each connection, you can reject or accept it depending on whether it's an allowed address or not. Or perhaps when you bind, bind to the internal IP address, though I am not sure that works. Just try it out anyway and let me know please
Nish
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
Nish [BusterBoy] wrote:
I guess on each connection, you can reject or accept it depending on whether it's an allowed address or not
You mean I add some IPs to the program and then when a connection is coming up I check if the IP is one of those which is added to the program?
Nish [BusterBoy] wrote:
Or perhaps when you bind, bind to the internal IP address
You mean, if the LAN IP of the computer is 192.168.244.138 then I assign the SOCKADDR_INs structure member sin_addr.s_addr to inet_addr("192.168.244.138")??
Do you understand me?
Rickard Andersson@Suza Computing
ICQ#: 50302279 (Add me!)
E-mail: nikado@pc.nu
I'm from the winter country SWEDEN!
|
|
|
|
|
Rickard Andersson wrote:
You mean, if the LAN IP of the computer is 192.168.244.138 then I assign the SOCKADDR_INs structure member sin_addr.s_addr to inet_addr("192.168.244.138")??
Yes, that's what I mean
Nish
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
Nish [BusterBoy] wrote:
Yes, that's what I mean
then I can tell you: It works!
So if I do this, nobody could connect to the server... cool!! Thank you for all other topics!
Rickard Andersson@Suza Computing
ICQ#: 50302279 (Add me!)
E-mail: nikado@pc.nu
I'm from the winter country SWEDEN!
|
|
|
|
|
Rickard Andersson wrote:
then I can tell you: It works!
Cool!
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
Looks good
Just in case your interested, here is a snippet of an old perl code.
It was an http deamon used as chat server, which can block unwanted IPs. Default setting below is allowing all incoming clients. I think you can imagine how to limit on only LAN IPs.
<br />
# AccessList: Define the access permitted list of IP's <br />
# (use komma as seperator).<br />
AccessList = *.*.*.*<br />
<br />
# DenyLis: Define the noaccess list, any IP matching a member of this<br />
# list will be denied access. The denylist is searched after the<br />
# accesslist (look above).<br />
DenyList = <br />
{
...
# Check to see if caller can access the server, if not kick him
if(!&CheckAccess($ENV{REMOTE_ADDR},@AccessList)) {
&ErrorMessage(*NS,$inp,403,"Access Denied"); exit 0
}
# Check to see if the caller is explicitly denied access to the server
if(&CheckAccess($ENV{REMOTE_ADDR},@DenyList)) {
&ErrorMessage(*NS,$inp,403,"Access Denied"); exit 0
}
...
}
# Test client IP against access lists, returns true if match
sub CheckAccess {
my ($who,@list) = @_;
my $pattern;
foreach $pattern (@list) {
$pattern =~ s/\./\\./g ; #replace . by \.
$pattern =~ s/\*/\\d\+/g; #replace * by \d+
return 1 if $who =~ /$pattern/;
}
return 0; #search failed
}
|
|
|
|