G
Guest
hi,
i'v been coding with c++/cli and i hit a terrible problem.
i created a class library project and add a ref class(abstract) with some
static member functions like:
////////////// CrawlerWrapper.h
public ref class CrawlerWrapper abstract sealed
{
public:
static void Initialize()
{
dele = gcnew DeleOnCrawlEnd(OnCrawlEnd);
gch = GCHandle::Alloc(dele);
ptrDele = Marshal::GetFunctionPointerForDelegate(dele);
}
static void Uninitialize()
{
gch.Free();
}
static int AsyncCrawl(String^ url)
{
return CCrawler::AsyncCrawl(
(CRAWLCALLBACK)ptrDele.ToPointer());
}
private:
static void OnCrawlEnd()
{
printf("%d\n",::GetCurrentThreadId()); // OK
printf("%d\n",Thread::CurrentThread->ManagedThreadId);//ERROR
};
delegate static void DeleOnCrawlEnd();
static DeleOnCrawlEnd^ dele;
static GCHandle gch;
static IntPtr ptrDele;
};
CCrawler is a class exported from a traditional DLL, CCrawler::AsyncCrawl()
accepts a function pointer as callback. After you call
CCrawler::AsyncCrawl(), it will create a thread to perform a task and then
when the thread has done, it will call the callback function to inform you
some information.
My problem is that my callback function CrawlerWrapper::OnCrawlEnd() crashes
when excutes the second line with a exception of
"System.StackOverflowException".
I can't figure out the root cause. Could anyone help me?
Many many thanks.
-Joe
i'v been coding with c++/cli and i hit a terrible problem.
i created a class library project and add a ref class(abstract) with some
static member functions like:
////////////// CrawlerWrapper.h
public ref class CrawlerWrapper abstract sealed
{
public:
static void Initialize()
{
dele = gcnew DeleOnCrawlEnd(OnCrawlEnd);
gch = GCHandle::Alloc(dele);
ptrDele = Marshal::GetFunctionPointerForDelegate(dele);
}
static void Uninitialize()
{
gch.Free();
}
static int AsyncCrawl(String^ url)
{
return CCrawler::AsyncCrawl(
(CRAWLCALLBACK)ptrDele.ToPointer());
}
private:
static void OnCrawlEnd()
{
printf("%d\n",::GetCurrentThreadId()); // OK
printf("%d\n",Thread::CurrentThread->ManagedThreadId);//ERROR
};
delegate static void DeleOnCrawlEnd();
static DeleOnCrawlEnd^ dele;
static GCHandle gch;
static IntPtr ptrDele;
};
CCrawler is a class exported from a traditional DLL, CCrawler::AsyncCrawl()
accepts a function pointer as callback. After you call
CCrawler::AsyncCrawl(), it will create a thread to perform a task and then
when the thread has done, it will call the callback function to inform you
some information.
My problem is that my callback function CrawlerWrapper::OnCrawlEnd() crashes
when excutes the second line with a exception of
"System.StackOverflowException".
I can't figure out the root cause. Could anyone help me?
Many many thanks.
-Joe