Advertisement

01.29.2008 at 07:56AM PST, ID: 23119633
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Managed C++ How to pass a pointer to a class instance to a static callback?

Tags: managed C++
So in my quest to integrate a native C++ dll callback into a managed C++ project, I have now succeeded (with much help!) to import the dll calls including the callback call into the project by the use of delegates. The callback is a static member function of a managed class, in fact the class of the only Form of that small .NET project.

Now my problem is that I don't know how to get access to the members of the managed class from the callback function. Indeed since it is a static function, I cannot use the handy "this->" function.

Back in the MFC days, I would have used the AfxGetApp() function to grant me access to the outside world, is there an equivalent in .NET?

Another option might be this: I can pass a "void* pContext" pointer to the dll function which registers the callback function. So I thought I should cast the "this" pointer to my Form class instance to a "void*" pointer and do the reverse from inside my callback.

The code looks like this :

////////////////code///////////////////////////////

typedef void (__clrcall *func_t2)(TestCamera2::Form1 ^const);//for casting from a Form^ type to a void* type

func_t fp2 = func_t(Marshal::GetFunctionPointerForDelegate(fp).ToInt32());//delegate to the callback function

m_lCallbackRegistration = CameraAddStreamingCallback(m_hCamera, fp2, func_t2(this));//this compiles fine

//////////////////////////////////////////////////////

Then in my callback I have to cast back my pContext pointer from void* to Form^.

I tried to do it the following way:

////////////////code///////////////////////////////

typedef TestCamera2::Form1 ^const (__clrcall *func_t3)(System::Void*);
func_t3(pContext)->Preview->Name = L"Preview";//doing something on a member of the Form class

//////////////////////////////////////////////////////

However I get the following compiler error which makes me think that my cast did not succeed:

error C2227: left of '->Preview' must point to class/struct/union/generic type

What am I doing wrong...?

Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: bobsinclare666
Solution Provided By: evilrix
Participating Experts: 2
Solution Grade: B
Views: 35
Translate:
Loading Advertisement...
01.29.2008 at 08:09AM PST, ID: 20769058

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.29.2008 at 08:12AM PST, ID: 20769096

Rank: Sage

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.29.2008 at 08:39AM PST, ID: 20769439

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.29.2008 at 09:03AM PST, ID: 20769749

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.01.2008 at 01:17AM PST, ID: 20795188

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.01.2008 at 01:21AM PST, ID: 20795204

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.01.2008 at 05:55AM PST, ID: 20796501

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080236-EE-VQP-29 / EE_QW_2_20070628