473,386 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

working with unmanaged C++

I'm hoping someone will be able to help me with an issue relating to working with unmanaged C++.

I've been able to get most things working with regard to mapping from unmanaged C++ to C#, but the area I'm having a problem with is with a C++ callback to a C# delegate. The delegate is being called and executing, but when the delegate ends and sends the return code to C++, I'm getting a Windows error. Nothing is being returned to the managed debugger and the app just dies.

I would really appreciate any help that could be provided. The following is what I've been working with. Thanks.

Expand|Select|Wrap|Line Numbers
  1. 3-d Party C++:
  2. _declspec(dllexport)  ULONG   NIrtd_startDataStream( 
  3.                                             NIrtd_tAPIauth    *authorization,
  4.                                             NIrtd_tQuery        *query,
  5.                                             ULONG                updateRate,
  6.                                             NIrtd_funCallback    callback,
  7.                                             void               *yourpointer,
  8.                                             NIrtd_tRequestId    *requestId);
  9.  
  10. /* Call back routine definition */
  11. typedef  ULONG (* NIrtd_funCallback) (
  12.                                      ULONG      return_code,
  13.                                      NIrtd_tRequestId        requestid,
  14.                                      NIrtd_stTableGroup *    tableGroup,
  15.                                      void *  yourpointer);
  16.  
  17.  
  18. C++ Wrapper:
  19. extern "C" __declspec(dllimport)  ULONG NIrtd_startDataStream_CLib(
  20.         AuthInfo_CLib        *authInfoStruct,
  21.         Query_CLib            *queryStruct,
  22.         ULONG                  updateRate,
  23.         NIrtd_funCallback   callback,
  24.         AppPtr_CLib          *appPtr,
  25.         Request_CLib         *requestStruct
  26. );
  27.  
  28.  
  29. C#:
  30.  public delegate uint RealTimeCallBack(uint return_code,
  31.         IntPtr requestId,
  32.         ref TableGroupStruct tableGroup,
  33.         ref IntPtr appPtr);
  34.  
  35.  private static RealTimeCallBack _RealTimeCallBack = null;
  36.  
  37.  private uint RealTimeCallBackHandler(uint return_code,
  38.         IntPtr requestId,
  39.         ref TableGroupStruct tableGroupStruct,
  40.         ref IntPtr appPtr)
  41.         {
  42.             try
  43.             {
  44.                 Console.WriteLine("server: Callback handler called");
  45.              }
  46.             catch(Exception ex)
  47.             {
  48.                 throw new Exception("RealTimeCallBackHandler: " + 
  49.                 ex.ToString() );
  50.             }
  51.  
  52.             return 0;
  53.         }
  54.  
  55. [DllImport("RtdApi.dll")]
  56. public static extern uint NIrtd_startDataStream_CLib(
  57.             ref AuthInfo authInfo,
  58.             ref Query query,
  59.             uint updateRate,
  60.             RealTimeCallBack callback,
  61.             ref AppPtr appPtr,
  62.             ref Request request);

As mentioned, the startDataStream_CLib is setting things up properly and the delegate is being fired, but it's after the delegate ends (after the closing brace) that the app dies.

Any ideas?

Thanks.

Juan
Mar 19 '07 #1
1 1296
kenobewan
4,871 Expert 4TB
It appears as though the problem you are having is with C++. Would you like me to move your question to the C++ forum, where you are more likely to receive expert help with C++?
Mar 20 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Bob Rock | last post by:
Hello, in the last few days I've made my first few attempts at creating mixed C++ managed-unmanaged assemblies and looking aftwerwards with ILDASM at what is visible in those assemblies from a...
4
by: Rachel Suddeth | last post by:
What is the difference between a managed/unmanaged resource, and how do you tell which is which? I'm trying to understand how to write some Dispose() methods, and we are supposed to put code that...
12
by: Vasco Lohrenscheit | last post by:
Hi, I have a Problem with unmanaged exception. In the debug build it works fine to catch unmanaged c++ exceptions from other dlls with //managed code: try { //the form loads unmanaged dlls...
1
by: Sparhawk | last post by:
Hi, my company is going to migrate a large VC++ application to .NET to make use of Windows Forms (the old class library is not updated any more). We are not planning to migrate the rest of the...
6
by: marek | last post by:
Hello All, we are doing a quite a big project that contains at the lowest level an unmenaged c++ classes. Above it there are managed wrappers and at the top there are ASP.NET pages. Can anyone...
6
by: Stephen Walch | last post by:
Our application environment consists of three basic layers: 1. Third-party unmanaged DLLs that were written before the CLR was invented and maintain a significant amount of information (including...
9
by: Amit Dedhia | last post by:
Hi All I have a VC++ 2005 MFC application with all classes defined as unmanaged classes. I want to write my application data in xml format. Since ADO.NET has buit in functions available for...
5
by: akash | last post by:
I'm having problems calling an unmanaged class from a managed wrapper. I suspect I'm missing something obvious, as I'm unfamiliar with C++ and classes are very simple. My unmanaged class is as...
2
by: Jon Slaughter | last post by:
How difficult is it for one to integrate unmanaged C++ into C#? I know for functions one can use DLLimport but how does one go about doing it for classes? Do I have to completely reimplement the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.