|
Thanks for the explanation
I was using a simple LoadIcon . I now switched to LoadImage with the 'desired size'.
Thanks again
|
|
|
|
|
hi
How to create a win32 static library and export a function?
with VC6 + sp4
thanks.
|
|
|
|
|
VC6 has a project type called 'Win32 Static Library'.
There is no need to export functions from a static library. Just provide a header file with a declaration.
Brad
|
|
|
|
|
I need to use a pointer to function in a generic class.
This is a peace of the code I've written:
// pointer to function declaration
void (*m_pNotifyDataAvailablity)();
// pointer to function assignment
void CMyClass::SetCallback(void(*p_pNotifyDataAvailablityCallback)(void))<br />
{<br />
m_pNotifyDataAvailablity = p_pNotifyDataAvailablityCallback;<br />
}
My problem is the following:
If I call the SetCallback method supplying a global function no problem occurs. When I try to supply a function member of CMyClass class the application doesn't compile and the following message is shown by the compiler:
error C2664: 'SetCallback' : cannot convert parameter 1 from 'void (void)' to 'void (__cdecl *)(void)'
None of the functions with this name in scope match the target type.
Can someone help me ??
Thanks a lot !!!
|
|
|
|
|
The reason this occurs is because the type of your function (the one which is a part of a class) isn't void(*func)(void).
Whenever you want to call a classe's function you need to call it in the context of an object of that class (i.e. supply a 'this' pointer), but when you'll try to call the function you received with SetCallback you won't have any 'this' (should the code would compile, which it doesn't
here's some code to help put you in the right direction:
(btw, this is also usable when you want a classe's function to run in it's own thread
<br />
class MyClass<br />
{<br />
public:<br />
void MyFunc(void);<br />
};<br />
<br />
<br />
void __cdecl worker(void *pVar)<br />
{<br />
((MyClass*)pVar)->MyFunc();<br />
}<br />
<br />
MyClass::MyClass()<br />
{<br />
worker(this);<br />
}<br />
<br />
<br />
What you need to do is seperate handling of global functions and class-contained functions.
I'm trying to understnad from your example what you were trying to do, perhaps you can define an abstract class 'IMyFunc', put a function 'MyFunc' there, then have all the classes you want to have this possible behaviour implement this class/interface and then you can call an external function, suplpy 'this' and have it call the function, or save the 'this' instead of the function pointer...
hmm, this came out abit confusing, perhaps you can elaborate mroe on waht you're trying to do
|
|
|
|
|
You need to change the callback function within the class to be static . You did not show all of the relevant code, so I can only guess as to what you might have.
void (*m_pNotifyDataAvailablity)();
class CMyClass
{
public:
CMyClass(){};
~CMyClass(){};
void SetCallback(void(*p_pNotifyDataAvailablityCallback)(void));
static void SomeCallback( void );
};
void CMyClass::SetCallback(void(*p_pNotifyDataAvailablityCallback)(void))
{
m_pNotifyDataAvailablity = p_pNotifyDataAvailablityCallback;
}
void CMyClass::SomeCallback( void )
{
AfxMessageBox("Howdy!");
}
...
CMyClass mc;
mc.SetCallback(CMyClass::SomeCallback); Otherwise, the compiler has no way of knowing that SomeCallback() is a member of CMyClass since it has no scope resolution operator.
|
|
|
|
|
If you call the SetCallback method supplying a function member of CMyClass class, you must declaring the function pointer as follows:
void (CMyClass::*m_pNotifyDataAvailablity)();
|
|
|
|
|
Hello all
I'm writing a console application in which I have to generate timer event at intervals 1 min,2 min,3 min,4 min and 5 minutes respectively. it's working fine upto 3 minutes interval but whenever I set 4 minutes or 5 minutes interval the timer event is generated immediately. Following is the code I'm using ...
LARGE_INTEGER liDueTime;
liDueTime.QuadPart=-600000000 * 3;// Generatiing timer event at 3 min interval
// Negative values indicate relative time
HANDLE hTimer=CreateWaitableTimer(NULL,TRUE,"WaitTimer");
SetWaitableTimer(hTimer, &liDueTime, 0, NULL, NULL, 0);
If I'm using -600000000 * 4 or 5 then the event is generated immediately. Can anyone help me in this?
Many thanks for your help.
Hari.
|
|
|
|
|
Since 600000000 * 4 is roughly 2^31 (maximum value of signed int ), it sounds like you are being plagued by OVERFLOW.
|
|
|
|
|
Hello David
Thanks for the reply. You're right the value is exceeding the range an integer can hold. But is there any way to solve my problem of setting time intervals.
If any one knows how to solve it, pls help.
Thanks
Hari.
|
|
|
|
|
Set the timer for one minute, and then each time the event is signaled (or the completion routine is called), increment a counter. When the counter is four, you know that four minutes have elapsed.
|
|
|
|
|
Hello David
Thanks for the reply, Using a counter solved the problem
Hari.
|
|
|
|
|
hi!
several days ago,I wrote my program with seh filter function using "_set_se_translator()",the debug version worked well as my expectation that it turned to my own exception filter specified in _set_se_translator() when the exception happened;but the release version did it as if there was no try_catch statement.why?
thanks!
|
|
|
|
|
You need to provide a bit more context about your code.
That said, I ran into something similar which may be the problem you're having. I had code similar to this:
int* pi = NULL;<br />
int i = *pi;
In debug builds, an exception was thrown from my SE handler and caught, but not in release builds. As it turned out, in release builds, the optimiser was correctly removing this code because it had no effect.
Not sure what you're doing, but if it's simple test case like mine, you might want to turn off the optimiser for that block of code:
#pragma optimize("", off)
Brad
|
|
|
|
|
I have a problem.there is a parent dialog, load two modeless dialog through the TAB control attached, only one modeless dialog show real-time,for don't move the modeless dialog in the tab controls,so the modeless dialog has only a Client,has no title bar.
When handle a button 's clicked command message in parent dialog, I want to trig a modeless dialog's button clicked event.So send message to the destination dialog e.g SendMessage(hModelessDialogWnd,WM_COMMAND,(WPARAM)IDC_BUTTONINMODELESS,0,0),but the destination show modeless dialog don't get the mesage and handle it.
1.How to get the handle of modeless dialog,beause the modelsess dialog has no title bar.
2.I attempt many method to get modeless dialog's pointer or handle.but debug it find don't get the modeless dialog's handle.
|
|
|
|
|
Hi,
is it necessary to initiate or reset LPTSTR zBuffer to zero after it was filled with a value?
Thanks, Mark
|
|
|
|
|
???
Don't try it, just do it!
|
|
|
|
|
zBuffer = 0; right??
Thanks, Mark
|
|
|
|
|
Yes, now you have given zBuffer the value 0.
If that makes any sense cant de deduced from what you have posted, as you failed to give any sort of helpful information.
So I think you know what you are doing.
Who is 'General Failure'? And why is he reading my harddisk?!?
|
|
|
|
|
I already created a SDI containg a dialog X with listbox, buttons..etc. Realise that i need a database as well, how do i start creating one and incorporate it into my SDI application? The interface dialog (for user to key in data) for this database will appear only when a specific button is pressed in dialog X. Urgent!
|
|
|
|
|
The easiest way is to create another SDI application with database support and note what gets added to the project. Add those items to your application. The biggest item will be a class derived from CRecordset .
|
|
|
|
|
Hey All,
Just wondering if anybody knows how to go about modifiying the http request header just before it's sent to the server. If I have an app with a CHttpView how would I go about viewing and modifying the header after somebody clicks on a link but before it's sent to the webserver.
I'm not exactly sure if OnBeforeNavigate2 is the one I should be using and I'm not sure how I go about modifying the Header (specifically the values that are "posted" to the server from a form (Is it CHttpArgList that I need to be dealing with?)).
Thanks in advance for any help lads.
Regards,
Brian Dela
IE 6 required: http://www.briandela.com[^] It works now.
|
|
|
|
|
1. Does anyone know if using templates causes classes to run slower in time versus there non-templated counter parts?
2. As I understand that templates allow for portability, is it wise to use them for time critical operations (eg. graphics processing, DSP, etc.)?
3. Are the STL classes fast?
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proff programs, and the Universe trying to produce bigger and better idiots. So far the Universe is winning." -- Rich Cook
|
|
|
|
|
RichardS wrote:
1. Does anyone know if using templates causes classes to run slower in time versus there non-templated counter parts?
The overhead for templates is at compile time. It manifests itself in two ways:
1/ slower build times
2/ code bloat
Slower Build Times for the most aren't a real problem, but with some libraries there may be a noticable slowdown. I noticed this mostly when dealing with boost::function. However, the benefits you get from templates far outweigh this in my opinion.
Code Bloat is caused by repeated instantiation of different types of templates making your compiled products bigger.
As for whether templates can make code faster at runtime, they can, but only if you are prepared to make sacrifices in other areas. For example, sometimes you can avoid the use of virtual functions altogether by using templates, which in tight inner loops may give you the speed increase you need.
Another area templates can make a significant performance difference is in compile time calculations - many matrix math libraries now use templated proxy classes to minimise copies.
Templates certainly shouldn't be any slower at runtime than normal classes, because they will eventually be converted to standard classes ( well, sort of ). It's certainly a matter of picking the right tools for the job.
RichardS wrote:
2. As I understand that templates allow for portability, is it wise to use them for time critical operations (eg. graphics processing, DSP, etc.)?
Again, performance depends on the situation, if you can prevent extra copies (look for information on Expression templates, or look at the code for boost::lambda or boost::ublas for good examples), you are likely to get significant speed improvements. If you need to matrix math (DSP) you may well get that extra performance you need.
Portability (as in operating system portability) is more generally supported by the use of the preprocessor, but it should be possible to use template specialisations to do the same thing - but I don't know if it would be worth the effort.
RichardS wrote:
3. Are the STL classes fast?
The STL classes were designed to be generic containers, so they aren't optimal in all situations. For most applications the effort and risk of writing and debugging custom containers is probably higher than that of using the STL. If you're sensible with the containers you can get extremely good performance out of them, eg/ store pointers (or even better, boost::shared_ptr's) to minimise the cost of copying containers. Also make sure you select the appropriate container for the job.
The STL learning curve isn't as steep as many other API's, and I strongly recommend this as a good way to get into using writing generic code. What you will find is that writing good generic code is harder than writing non-generic code, but it's (generally )almost as easy to use.
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
Thank-you for your response.
Andrew Walker wrote:
1/ slower build times
2/ code bloat
If these are the main 2 time factors templates seem quite good.
For templates I generally use Explicit Instantiation of the template class which seems to aid in the compile and link times (although for big projects this leads to handling a large number of template instaniations).
Andrew Walker wrote:
Portability (as in operating system portability) is more generally supported by the use of the preprocessor, but it should be possible to use template specialisations to do the same thing - but I don't know if it would be worth the effort.
Oops, I was more thinking along the lines of reuse. We do work in embedded controllers in which each platform has different hardware, so code is ported and reused on each platform. Thus template's would allow us to extend products with out hampering previous released platforms.
You seem to speak quite an indepth knowledge of the boost library. Is it good for speed?
Rich
"Programming today is a race between software engineers striving to build bigger and better idiot-proff programs, and the Universe trying to produce bigger and better idiots. So far the Universe is winning." -- Rich Cook
|
|
|
|