Solved

WPF project and COM objects

Posted on 2015-01-12
6
222 Views
Last Modified: 2015-01-12
Hi Experts,

I have a WPF application that talks to a CLR class library that calls into C++.  The reverse is proving more difficult.  I've seen the method where you can pass a delegate as function pointer, but I find that too intrusive and need to change my C++ implementation to support it.

So I think my current best option might be to turn a class in my WPF application into a COM server.  I have done so, but since this is a WPF application, there is no dll output.  Clearly I could create another intermediate class library just for this COM object, and then use this class library from my WPF application.  But is there a way to use the exe instead of a dll to register in WIndows?

Also, if I do use an intermediate class library, how do I get this COM object to talk to the rest of the WPF application?  I can't instantiate it in my WPF program and have it CoCreated by the C++ native code that will be creating it as well....  

Thanks,
Mike
0
Comment
Question by:thready
  • 3
  • 3
6 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 40545871
>> The reverse is proving more difficult.

Have you considered just passing windows messages to the WPF app by the C++ layer? Not sure if that is applicable, but you can pass a lot of stuff via the message parameters.
0
 
LVL 1

Author Comment

by:thready
ID: 40545880
I did not think of that.  That's a much simpler idea!  I can keep this out of the cross platform c++ and inside of the class library as well...

I'm still curious about how one is supposed to CoCreate a class and have the class implementation talk to WPF...   It's created by the C++ side, so then it's in-process.  Does this mean that callbacks from the COM class will need to be static?  (I wonder if I'm not making sense here)....
0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 500 total points
ID: 40545886
You could still pass a C# delgate sink to the class in question upon construction or via an 'InitializeContext()' method after creating it - yet it is still a bit  to vague to say 'just do it'.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:thready
ID: 40545900
I don't really understand that method.  It makes sense to me, but how to do it with a .lib...  I don't know...  I'm starting to lose interest in trying to keep all business logic in c++ so that it's reusable everywhere.  Too time consuming- and what does it give me?  Not that much in the end.  I just wish my code base would never have to be touched again... But it seems I keep writing the same kinds of things for new projects.

If I do everything in C#, I'll be much better off.  Just no cross-platform stuff.  Please talk me out of dropping this if you think it's all worth it?  :-)
0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 500 total points
ID: 40545903
If you can do most of the stuff in C#, even the better - yet since you are still vague about your setup, it is hard to give any advice. If e,g, your underlying C++ lib&dll can take a target window handle that receives the messages I mentoined earlier, you could pass structs/classes via the 'lParam' parameter (either by custom messages or by utilizing WM_COPYDATA) that are close to give you the flexibility you might need.
0
 
LVL 1

Author Closing Comment

by:thready
ID: 40545909
I have/had a goal to write all my business logic in pure cross-platform c++, with the idea that c++ was the most common denominator between systems with the best chance for reuse.  However, I don't have much code, but wanted to write everything one last time.  I think I'm not getting that much out of this goal though.  And I do like C# best.  I think in the name of completing projects fast with less headaches, I'll stick to C# for now....   and hopefully not kick myself later on..
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now