|
Can some one please help me out in this
|
|
|
|
|
You cannot expect the cursor to change while you have yourself blocked the message processing loop. For the cursor to change you must return and then let the message processing loop handle the cursor change message.
As far as I understand you need a separate thread for doing the time taking processing or do it in OnIdle
Hope this helps
|
|
|
|
|
I have a project in which I was using a view using a CTabCtrl. I ran into some issues turning tabs on and off and my searching led me to the CPropertyView described here: Property Sheet View[^]
I am writing here because the article is old and probably not being maintained. The original was written for VC 6. I have compiled the demo projects just fine under both VC 6 and VC 2005.
When I included CPropertyView in my project and attempted to compile, I got three errors which are real head scratchers. In my class derived from CPropertyView, I get the following errors:
C2248: 'CPropertyView::GetThisMessageMap' : cannot access protected member declared in class 'CPropertyView'
C2352: 'CPropertyView::AssertValid' : illegal call of non-static member function
C2352: 'CPropertyView::Dump' : illegal call of non-static member function
The C2248 error comes up with the END_MESSAGE_MAP() macro. I tried commenting out everything in the message map and I still got the error.
I have carefully checked the syntax and AssertValid and Dump are declared and called identically in this class as in all others. There is a slight variation between VC6 and VC2005 in that VC2005 has an extra #ifdef for Windows CE, but the error happens whether the ifdef is there or not.
I found a Microsoft Knowledge Base article (Q243351) that talks about the C2248 error happening when the /Za flag is used in the compiler, but I'm not using that flag.
I'm sure the answer is something simple, but I've run into a brick wall.
Bill
|
|
|
|
|
Have you put a DECLARE_MESSAGE_MAP in your derived class?
[edit]Also - I presume you've inherited publicly from CPropertyView?[/edit]
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
DECLARE_MESSAGE_MAP is there. I was tracking down another compiler error and stumbled across the problem. When I converted the class as derived from CFormView to CPropertyView, I had updated all the references to CFormView except 1. I don't know why the compiler didn't see that as a problem, but when I changed that, it compiled.
I'm having some other problems now. It appears that something in the parent class is causing a memory corruption in the derived class. It was blowing up when I tried to call Clear() for a COleVariant class variable. When I looked at it in the debugger, it was set to something strange. In the class declaration, I moved the COleVariant to the end of the fire and it ran Clear() fine. However, it now blows up when calling SetWindowText() for a CEdit variable.
Tracing down into the debugger, everything looks fine until
m_pCtrlSite->;SetWindowText(lpszString);
I try to trace into it, but I get an access violation reading location 0x00000000. The issue is almost certainly caused by something in CPropertyView because the program runs just fine through that point with the old TabView.
What tools are available to figure out what's corrupting memory?
Bill
|
|
|
|
|
wdolson wrote: m_pCtrlSite->;SetWindowText(lpszString);
I hope that first semi-colon's just a typo in the message
First thing - I presume you're using a Debug rather than Release build for your debugging (strange things can appear to happen when you debug a Release build).
If it is a Debug build, try setting a Data Breakpoint on the thing that's changing unexpectedly - that should be triggered when the data changes value.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Yes, the semi-colon was a typo. When I copied and pasted the code, it turned the arrow head into > and I didn't delete the semi-colon.
It is also being debugged in debug mode. I was putting a breakpoint where it was changing unexpectedly. The underlying code appeared to be getting corrupted.
This problem appears to have gone away when I fixed the order with which I created the tabs. I noticed I had two reversed and fixed it. That made the problem go away mysteriously. I'm not sure why having the tabs out of order caused the SetWindowText() function to get corrupted, but I have seen stranger things.
I once spent two weeks trying to find a bug in some hardware I designed. The thing just would not work. One morning, it just started working. My lead predicted it would be back and I had to agree with him. The hardware went into production and nobody ever saw that bug again. The debugging gnomes is the only explanation I have. (I'm feeling old, I just realized that was more than 20 years ago...)
Thanks anyway,
Bill
|
|
|
|
|
|
Hi,
Suppose I have a class
Class ABC
{
void DO();
}
I want to do the following;
void main()
{
ABC Object[20];
for(int i=0;i<20;i++)
createthread(Object[i].DO); //So 20 Threads are created here.
}
I was able to do the above with boost library but unfortunately Visual C++ 2008 has some issues with Boost::threads package. Microsoft states that they wouldnt be able to fix the issue.
Is there any other way I can implement the above?
Thanks
|
|
|
|
|
jobin007007 wrote: Is there any other way I can implement the above?
In addition to fixing the syntax errors (there are at least 5), you'd need to make DO() a static member, correct its prototype, and make it public (unlike structs, class members default to private ).
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
I didnt mean to type an actual compiling code. What I meant to do is show a generic example. This could apply to any language. The createthread is just a generic, not an actual function. What I mean to ask is there any way of acheiving the below with other than boost librarys.
ABC Object[20];
for(int i=0;i<20;i++)
createthread(Object[i].DO); //So 20 Threads are created here.
Using the boost library, you can do the above and DO() does not need to be static. But it has some problems like i meantioned in the earlier post
I think the TR1 implementation of C++ also alows the above code. But do you know of anything in Visual Studio 2008 or any other widely used library that can do the above?
Thanks
|
|
|
|
|
jobin007007 wrote: But do you know of anything in Visual Studio 2008 or any other widely used library that can do the above?
No extra library is required. Your code will work by using CreateThread() .
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
If you want use CreateThread() Win32 API then must write additional static function to satisfy CreateThread()'s calling convention.
Like;
#include <windows.h>
class ABC {
HANDLE m_child;
public:
static DWORD __stdcall DO(void* p) {
((ABC*)p)->DoReally();
};
void DoReally() {};
};
void main()
{
ABC Object[20];
HANDLE childHandles[20];
DOWRD childIds[20];
for (int i = 0; i < 20; i++) {
childHandles[i] = CreateThread(NULL, 0, Object[i].DO, &Object[i], 0, &childIds[i]);
}
}
But CreateThread() do not mention C runtime, so I recommend _beginthreadex() runtime function to call.
In general, if you want to make thread with some windows api, you should make some entry point matching its api function interface.
|
|
|
|
|
oh, no need m_child member for class ABC.
|
|
|
|
|
jobin007007 wrote: unfortunately Visual C++ 2008 has some issues with Boost::threads package
Really? Like what, pray tell? I've used VS2008 with Boost.Threads and I'd like to know what issues I might encounter...
Here's how I've implemented the pattern you want in the past:
class Updater
{
public:
static Updater* StartUpdate()
{
Updater* u = new Updater();
HANDLE hThread = (HANDLE)_beginthread(Updater::ThreadProc, 0, (LPVOID)u);
return u;
}
static void ThreadProc(void* lpvUpdater)
{
Updater* updater = (Updater*)lpvUpdater;
updater->DoUpdate();
}
void DoUpdate()
{
}
};
The thread function is Updater::ThreadProc. This is passed an Updater instance pointer, which it uses to call the member function you actually want to call.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
|
Ah - so it's a C++/CLI issue - well, that ain't going to worry me - I use vanilla C++
But anyway - it only affects you (IIUC) when you statically link against Boost.Threads. If you put this line before any Boost #includes, then Boost will automatically link against the DLL.
#define BOOST_THREAD_DYN_DLL
I've just tested this with a little sample program (built with VC2008) which had this code compiled with /clr:
#include "stdafx.h"
using namespace System;
extern void flibble();
int main(array<System::String ^> ^args)
{
Console::WriteLine(L"Hello World");
flibble();
return 0;
}
and this code compiled as native (against Boost 1.37.0)
#define BOOST_THREAD_DYN_DLL
#include <boost/thread.hpp>
void ThreadFunc()
{
for(int i=0;i<INT_MAX;++i)
;
}
void flibble()
{
boost::thread t(&ThreadFunc);
t.join();
}
It ran successfully, but if I removed or commented out the #define , it crashed on start-up. So - there was probably no need to dump Boost
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Oh great. I am gonna test this out tommorow.
But the CLI portion of my project is Dynamic Library type with MFC in a Shared DLL.
I am not sure what my C# Project type is.
When you say But anyway - it only affects you (IIUC) when you statically link against Boost.Threads. If you put this line before any Boost #includes, then Boost will automatically link against the DLL.
1) what do you actually mean? Would you be able to make the meaning clearer?
2) Why is Boost statically linking with my library? or is vice versa? what does that actually mean?
3) What is difference between static and dynamic linkage.
It would be really great if you could answer these questions.
|
|
|
|
|
jobin007007 wrote: 3) What is difference between static and dynamic linkage.
Static linking = link against a .lib containing object file - the object files are incorporated into your .exe or .dll
Dynamic linking = link against a .lib that references a DLL - your .exe or .dll will call the DLL when it calls the functions from the library.
jobin007007 wrote: 1) what do you actually mean? Would you be able to make the meaning clearer?
Boost (on Windows) has this really cool mechanism which automatically specifies which Boost libraries the linker should use when making your .exe or .dll. This takes into account various factors like a) what compiler you're using, b) (for Visual C++) what C run-time you're using, c) whether you're building a Debug or Release build. The one thing you have control over is whether a dynamic or static version of the Boost library is used. By using the line I gave you, you are telling Boost that you want to use the DLL version of Boost.Threads, not the other one. Boost will then tell the linker to use the DLL version of Boost.Threads.
jobin007007 wrote: 2) Why is Boost statically linking with my library? or is vice versa? what does that actually mean?
Your library is statically linking the Boost library. This happens because by default, Boost libraries automatically get statically linked.
HTH!!!
jobin007007 wrote: I am not sure what my C# Project type is.
That doesn't matter.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Would you able to tell me how to adapt my code to the code you wrote earlier?
Class ABC
{
int a;
int b;
void DO()
{
this.a="";
this.b="";
this.capture();
}
void capture()
{
}
};
void main()
{
ABC Object[20];
for(int i=0;i<20;i++)
createthread(Object[i].DO); //So 20 Threads are created here.
}
I am unsure as of how to use your example in my code.
|
|
|
|
|
There are so many ways...here's one
void MyThreadProc(void* objectAsVoidPtr)
{
ABC* object = (ABC*)objectAsVoidPtr;
object->DO();
}
void main()
{
ABC Object[20];
for(int i=0;i<20;i++)
_beginthread(MyThreadProc, 0, (LPVOID)Object+i);
}
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
#include iostream; //can't paste the << >> things here
#include string;
int main()
{
//works, from what i can see, because you cant compile "int someArray[] = {}" or "int arr[0];" because you cant allocate a 0-length array according to vs.net errors. So your guarenteed atleast 1 item in the array for "sizeof(_array[0])" to always find an item. this is the alternative to doing sizeof(int) or passing the type of the array to the macro.
#define ARRAY_LENGTH(_array) (sizeof(_array)/sizeof(_array[0]))
int someArray[] = {1, 2, 3, 4};
for(int i = 0; i < ARRAY_LENGTH(someArray); i++)
{
std::cout<<*(someArray + i)<
|
|
|
|
|
ARRAY_LENGTH macro is always ok for real array but not for pointer.
By the way, ARRAYSIZE() macro is predefined in windows.h of some newer sdk and it looks the same form as above.
|
|
|
|
|
wow norish i had no idea about that macro :P when i read that sizeof returned the number of bytes used by an array, i figured if i just divided by the size of the datatype used that i could get the length.
|
|
|
|
|
If you want a type-safe mechanism for getting the number of elements in an array, you might consider this:
#include <iostream>
template<class A, size_t N>
inline size_t ArraySize(const A ( & )[N]) { return N; }
template <typename T>
struct array_info
{
};
template <typename T, size_t N>
struct array_info<T[N]>
{
typedef T type;
enum { size = N };
};
int main()
{
typedef int (MyArray)[120];
int a[120];
float b[120];
std::cout << ArraySize(a) << std::endl;
std::cout << ArraySize(b) << std::endl;
std::cout << array_info<MyArray>::size << std::endl;
}
Here you have mechanisms for getting the number of elements in an array variable (function ArraySize ) or an array type (struct array_info ). And (unlike the macro version) these two won't compile if given a pointer variable/type - the power of pattern matching sees to that
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|