Re: Would C++/CLI solve PInvoke problems that C# has in this situation? What is the advantages using C++/CLI then C# when PInvoking umanaged C++ Code. Major problems here.
- From: "Mohamed Mansour" <m0@xxxxxxxxxxxxxxxx>
- Date: Mon, 10 Dec 2007 23:49:56 -0500
Hi Jeffrey,
Since I cannot code this at home, I would have to go back to the University Lab tomorrow and use their equipment. It is around $10,000 for the hardware. I am doing this in my spare time to open opportunities for .NET programming for research (I just graduated this morning from Software Engineering).
I might try another approach other than GC.KeepAlive, maybe I have to pin the Callback since the memory space gets lost after the first loop.
But Let me rephrase my problem. The application CRASHES after access the callback once in the Asynchronous Call. The Asynchronous method "deviceScheduleAsynchronous" in C++ has an infinite loop which poll data from the device. And That method is an infinite loop which is in its own thread. All that is in the unmanaged code that the manufacturer provided. The only thing that is visible to the consumer is :
void deviceScheduleAsynchronous (SchedulerCallback pCallback, void *pData,unsigned short nPriority)
long deviceScheduleSynchronous (SchedulerCallback pCallback, void *pData, unsigned short nPriority)
The C# Pinvoke are deviceScheduleAsynchronous(SchedulerCallback pCallback, IntPtr pData, ushort nPriority); Where SchedulerCallback is a delegate. Exact same for deviceScheduleSynchronous .
deviceScheduleSynchronous doesn't crash, but deviceScheduleAsynchronous crashes. It crashes after the first loop.
I will go back to the lab tomorrow and try the following. Maybe I have to pin the object in the Garbage Collector like the following:
1. deviceScheduleAsynchronous(IntPtr pCallback, IntPtr pData, ushort nPriority);
2. SchedulerCallback sc = new SchedulerCallback(MyCallBack);
3. IntPtr scPtr = GCHandle.Alloc(sc);
4. deviceScheduleAsynchronous(scPtr, IntPtr.Zero, 0);
I will do a stack trace tomorrow as well.
Thanks!
--
Regards,
Mohamed Mansour
Microsoft Student Partner
""Jeffrey Tan[MSFT]"" <jetan@xxxxxxxxxxxxxxxxxxxx> wrote in message news:tTxLgk6OIHA.6908@xxxxxxxxxxxxxxxxxxxxxxxxx
Hi Mohamed,.
Thanks for your feedback.
With the current information available, it is hard for us to say the root
cause. I also do not believe C++/CLI interop can help to resolve this
problem if the problem lies in the unmanaged side. C++/CLI uses C++ interop
technology to marshal between managed and unmanaged code and it provides
better performance than normal C# p/invoke. Also, it has the advantage of
convenient for interop.
Anyway, I think we have to find out the root cause for your crash first. I
am not sure why the exception you got did not make sense. Can you provide
the detailed stack trace of your crash? For this type of post-mortem
debugging, it is better to use windbg to get the unmanaged/managed mixed
stack trace. Please follow the steps below to obtain a stack trace for
analysis:
"How to debug application crash/hang in production environment?"
http://blogs.msdn.com/msdnts/archive/2006/11/24/how-to-debug-application-cra
sh-hang-in-production-environment.aspx
In addition to the stack trace, you may also provide the exception
information in the debugger output. Also, you may input "!gle" and
".lastevent" commands to understand the last few events before the failure.
Thanks.
Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
- Follow-Ups:
- References:
- Would C++/CLI solve PInvoke problems that C# has in this situation? What is the advantages using C++/CLI then C# when PInvoking umanaged C++ Code. Major problems here.
- From: Mohamed Mansour
- Re: Would C++/CLI solve PInvoke problems that C# has in this situation? What is the advantages using C++/CLI then C# when PInvoking umanaged C++ Code. Major problems here.
- From: Willy Denoyette [MVP]
- Re: Would C++/CLI solve PInvoke problems that C# has in this situation? What is the advantages using C++/CLI then C# when PInvoking umanaged C++ Code. Major problems here.
- From: Mohamed Mansour
- Re: Would C++/CLI solve PInvoke problems that C# has in this situation? What is the advantages using C++/CLI then C# when PInvoking umanaged C++ Code. Major problems here.
- From: Willy Denoyette [MVP]
- Re: Would C++/CLI solve PInvoke problems that C# has in this situation? What is the advantages using C++/CLI then C# when PInvoking umanaged C++ Code. Major problems here.
- From: Mohamed Mansour
- Re: Would C++/CLI solve PInvoke problems that C# has in this situation? What is the advantages using C++/CLI then C# when PInvoking umanaged C++ Code. Major problems here.
- From: "Jeffrey Tan[MSFT]"
- Would C++/CLI solve PInvoke problems that C# has in this situation? What is the advantages using C++/CLI then C# when PInvoking umanaged C++ Code. Major problems here.
- Prev by Date: Re: Using SQlite in c#
- Next by Date: Re: using = <type> directive
- Previous by thread: Re: Would C++/CLI solve PInvoke problems that C# has in this situation? What is the advantages using C++/CLI then C# when PInvoking umanaged C++ Code. Major problems here.
- Next by thread: Re: Would C++/CLI solve PInvoke problems that C# has in this situation? What is the advantages using C++/CLI then C# when PInvoking umanaged C++ Code. Major problems here.
- Index(es):
Relevant Pages
|