|
You need to create the second HBITMAP to be the same size, copy them both into DC's and then do a BitBlt between them. If they are both DIBSections, I'd presume you can create the second one the same size as the first and memcpy the bits from one to the other.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
Thanks for the response Christian, I would love to be able to memcpy the bits from the one HBITMAP to the other (they will both be DIBSections and they will both be the same size). But how does it work, do I have to create a new HBITMAP first using CreateDIBSection and then use memcpy? If this is correct, how do I use memcpy in that situation, without creating a memory leak from losing the pointers to the original "bits". I would very much like it if you could elaborate a little bit on this direction of solution,
Many thanks, again
Alan.
"When I left you I was but the learner, now I am the Master" - Darth Vader
|
|
|
|
|
memcpy copies the contents of the memory, so what happens is this:
1/ You create a new DIBSECTION the same size and bit depth as the first.
2/ You now have two DIBSECTIONs and two pointers to byte arrays, which are the same size. You use memcpy, which copies the contents of one byte array into the other. You're not allocating memory, you're copying the values of the pixels into the location that already holds the values of the bitmap as it was created, making them identical to the first.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
Many thanks Christian, I`m off to implement your suggestion, I`ll get back to you and amend this message with the results.
Thanking you lots,
Alan.
"When I left you I was but the learner, now I am the Master" - Darth Vader
|
|
|
|
|
No worries - glad to help.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
I'm trying to figure out how to receive/send data of different types (including standard types AND my own objects) not using MFC CSocket-CSocketFile-CArchive trio. I've got the socket part already, now I want to use << >>
to actually start transferring data. I'm new to STL but have a feeling
that's the way to go. Right? How? Or no?
|
|
|
|
|
I don't quite catch your point, but if what you're looking for is iostream-like classes for data communication thru sockets, then please note that the C++ standard does not cover this issue. Nevertheless, iostream was designed with such kind of extensions in mind, and there are a number of libraries out there to do socket communications à la iostream. To name a few:
- Socket++ is probably the most popular library in this area. Originally written by Gnanasekaran Swaminathan for UNIX environments, it's been later ported to Win32 by Greg Lavender.
- Maciej Sobczak releases an iostream-compatible socket wrapper along with his article on the current (December 2001) C/C++ Users Journal issue, which in addition features other articles about C++ and sockets you might find interesting to look at.
- socketstream library, written by a Korean guy whose name I haven't been able to decipher Haven't tested myself, nor do I have any reference about it.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
hi, everybody
I'm using CArchive constructed on CSocketFile and i'm
trying to serialize CMsg objects like this :
(note : ar is my archive and msg my message to serialize)
ar.WriteClass(msg.GetRuntimeClass()); //it works fine
ar.WriteObject(&msg); //works fine
and at the other side of the network i have :
CRuntimeClass * pClass = ar.ReadClass(); //this throw me an error CArchiveExceptionError::badIndex
Any ideas about this ?
|
|
|
|
|
hai all,
i am a new person who is working in vc++ fro 2 month
i am facing some problem in starting the dialog box in windows machine. whila compilng it's giving this messages is any thing missing.
Loaded 'D:\etnnew\ethnew\Release\ethnew.exe', no matching symbolic information found.
Loaded 'C:\WINNT\System32\ntdll.dll', no matching symbolic information found.
Loaded 'C:\WINNT\SYSTEM32\MtoMLAN.dll', no matching symbolic information found.
Loaded 'C:\WINNT\SYSTEM32\KERNEL32.DLL', no matching symbolic information found.
Loaded 'C:\WINNT\SYSTEM32\USER32.DLL', no matching symbolic information found.
Loaded 'C:\WINNT\SYSTEM32\GDI32.DLL', no matching symbolic information found.
Loaded 'C:\WINNT\SYSTEM32\ADVAPI32.DLL', no matching symbolic information found.
Loaded 'C:\WINNT\SYSTEM32\RPCRT4.DLL', no matching symbolic information found.
Loaded 'C:\WINNT\SYSTEM32\WINSPOOL.DRV', no matching symbolic information found.
Loaded 'C:\WINNT\SYSTEM32\COMCTL32.DLL', no matching symbolic information found.
Loaded 'C:\WINNT\SYSTEM32\WSOCK32.DLL', no matching symbolic information found.
Loaded 'C:\WINNT\SYSTEM32\WS2_32.DLL', no matching symbolic information found.
Loaded 'C:\WINNT\SYSTEM32\msvcrt.dll', no matching symbolic information found.
Loaded 'C:\WINNT\SYSTEM32\WS2HELP.DLL', no matching symbolic information found.
Loaded 'C:\WINNT\SYSTEM32\mfc42.dll', no matching symbolic information found.
LDR: Automatic DLL Relocation in ethnew.exe
LDR: Dll qaphooks.dll base 10000000 relocated due to collision with C:\WINNT\System32\MTOMLAN.dll
Loaded 'C:\WINNT\SYSTEM32\qaphooks.dll', no matching symbolic information found.
Loaded 'C:\WINNT\SYSTEM32\RNR20.DLL', no matching symbolic information found.
Loaded 'C:\WINNT\SYSTEM32\RPCLTC1.DLL', no matching symbolic information found.
First-chance exception in ethnew.exe (NTDLL.DLL): 0xC0000005: Access Violation.
Loaded 'C:\MOUSE\SYSTEM\ccmsghk.dll', no matching symbolic information found.
Loaded 'C:\WINNT\SYSTEM32\msidle.dll', no matching symbolic information found.
The thread 0x201 has exited with code 120 (0x78).
The program 'D:\etnnew\ethnew\Release\ethnew.exe' has exited with code 120 (0x78).
Suleman
|
|
|
|
|
Are you sure it is compiling. It looks more like it is debugging and can't find debug info.
-Matt Newman
-Matt Newman
|
|
|
|
|
How do you mean W95 only ? The system dll's being loaded are under c:\WinNT, and 'no mayching symbolic information found' is not unusual or broken.
You need to post some code. What are the details of your project ? How was it created ?
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
I have a class that implements the thread operation(not
inherited from MFC)-"MyCDialogThread" - that open a CDialog on it's run method with either DoModal or create.
I create that threat from another thread and i need to kill
my "MyCDialogThread". How can that be done?
|
|
|
|
|
Can you send a WM_CLOSE message to that CDialog ?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
No. in my case - i open the dialog with DoModal and that thread donot response to any sendmessage.
The other thread that should send the SendMessage to my thread could not be proccessed until my thread(that own the CDialog)could execute, but it couldn't because my thread is blocked until it will be finished.
I read about it in Josheph M.Newcomer article "Using Worker Threads" here in the Code Project.
|
|
|
|
|
Try with TerminateThread
best Regards
Carlos Antollini.
Sonork ID 100.10529 cantollini
|
|
|
|
|
Can you use a UI thread instead of a worker thread for the owner of the CDialog (and proceed then with sending WM_CLOSE )?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi, All!
=======
What is IDISPATCH ?
What should I do with it?
How to use it?
10x
BTW: come to #CodeProject on DalNet (mIRC)
|
|
|
|
|
IDispatch is a way for pointer-challanged programming languages to call COM components. It simply gives an extra layer of abstraction to the calling procedure.
Assuming you know what interface your IDispatch you could use it in two steps:
1) Get DISPID:s for the functions you want to call with GetIDsOfNames
2) Set parameters and call Invoke with the chosen DISPID.
Example: Calling a function showWindow(BOOL show) in IDispatch idispatch
DISPID dispid;
OLECHAR* name = L"showWindow";
idispatch->GetIDsOfNames(IID_NULL, &name, 1, GetUserDefaultLCID(), &dispid);
VARIANT arg;
arg.vt = VT_BOOL;
arg.boolVal = VARIANT_TRUE;
DISPPARAMS param = {&arg, NULL, 1, 0};
idispatch->Invoke(dispid, IID_NULL, GetUserDefaultLCID(), DISPATCH_METHOD, ¶m, NULL, NULL, NULL);
Or you could just QueryInterface for the interface you want..
/moliate
|
|
|
|
|
Got a complex class which depends on data files opened in the constructor. Does anyone have any neat ideas about how to handle error conditions? If the files don't exist I don't want the object to be created but I can't see how to do it.
TIA
Dave Cross
|
|
|
|
|
I don't have any neat ideas, I just want to point out that the constructor is not the best place for doing a large amount of work that might fail.
Michael
|
|
|
|
|
Exceptions. Just throw an exception when your constructor fails and catch it in the code contructing the object. I think that is actually the *only* right way to do it.
Cheers
Steen.
"To claim that computer games influence children is rediculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
Doing a lot of work in the constructor is generally considered bad OOP, but if you must do it than exception handling is the best technique to deal with errors, at least if this is going to be a widely distributed class.
"But, daddy, that was back in the hippie ages..." My twelve year old son - winning the argument.
"Stan, you are an intelligent guy who responds in meaningful ways" Paul Watson 16/10/01
|
|
|
|
|
IMHO doing a lot of work in ctors can't be (in general) consider bad OOP.
A design approach that works nicely with OOP and ctors is the idea of having the objects keep an invariant condition that holds for the entire lifespan of the object. This invariants help deal with the object and ease the implementation of their methods --you can think of invariants as a semantic contract with a class instance.
So, if initializing an invariant condition takes a lot of work due to the complexity of the invariant, the proper place to do that is precisely the ctor. After construction you know everything's in place, without resorting to init() methods and stuff like that. If you cannot grant that invariant on construction time, throw ing is the exact thing to do.
I would even dare to say that huge ctors (if properly backed up by meaningful semantics) provide for richer, easier to use classes.
Joaquín M López Muñoz
Télefónica, Investigación y Desarrollo
|
|
|
|
|
I'm not religious about it one way or the other. I certainly understand that one methodology will never solve every possible design problem. My personal philosophy though remains that a complex ctor made dependent upon exception handling is generally not superior to a simple "init()" call. But I am not prepared to say that it is always inferior. I have always found it very convenient to be able to return a complex object to its original default state at any point in its lifetime with an initialization function of some kind. You just have to remember that the init() cannot be virtual if you intend to use it from the ctor.
"But, daddy, that was back in the hippie ages..." My twelve year old son - winning the argument.
"Stan, you are an intelligent guy who responds in meaningful ways" Paul Watson 16/10/01
|
|
|
|
|
Effectively throwing an exception is the way to let the client knows about the error. If lot of stuff is done in the constructor, you probably also want to do some cleanup if an error occurs and in that case one of the following design may help (choose the one that best fit).
1) Uses ressource wrapper classes for ressources (like std::auto_ptr for pointers). Thus every member that allocate a ressource (memory, handle) is a wrapper.
2) Uses the pimpl idiom. The implementation class should then have a trivial constructor that may not have an error (set pointer to NULL, handle to INVALID_HANDLE_VALUE,...) and an initialisation function that do the actual initialisation.
class VClass {
private:
class VImpl;
VImpl *m_pImpl;
};
class VClass::VImpl {
public:
VImpl(); // Simple initialisation only
~VImpl(); // Release every allocated ressource
void init(); // Complex initialisation
};
VClass::VClass() {
std::auto_ptr<VImpl> pImpl = new VImpl;
pImpl->init();
m_pImpl = pImpl.release();
}
VClass::~VClass() {
delete m_pImpl;
}
3) Derive from a class that hold the ressource and do the initialisation in the derived class constructor by calling an initialisation function in the inherited class. That way if an exception is thrown from the derived class, the base class that hold the ressource will have its destructor called since it is a completly constructed object.
4) Uses wrapper class in the constructor body and at the end of the constructor body transfer the ownership from the wrapper class to the associate member of the class.
I do not like complex constructor without using one (or more) of the design above since it complexify the constructor error handling a lot (for ex. closing file that have been opened up to that point).
Note that the patterns #2 and #4 above typically allows to reduce compilation depedencies in the header file... which is often desirable when a class is complex.
Philippe Mori
|
|
|
|