473,328 Members | 1,568 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,328 software developers and data experts.

Question about managed and unmanaged codes in VC++.NET

45
Hi all,

I am developing a Windows Form Application in VC++. I am using using Visual Studio 2005. My project requires me to use the Boost Libraries [for more info visit www.boost.org] These boost libraries are unmanaged code, where as my application itself is managed code. I have a seperae set of unmanaged classes doing the bulk of the work. Now I want to use these classes form the managed class of my application.

Let me give a example... Say I have a form and a button on it. I want to call a perticular function form the unmanaged code when the button is clicked. How do I do that? Or say when the button is clicked and if at all, I am able to call the function which is returning, say a array. How do I get the values of the elements in the array populaed into a ListBox?

Please help me...
I am new to VC++...
Thanks
Mar 5 '08 #1
2 1027
misza
13
Hi,

I also started using managed c++ not so long ago, so maybe someone more experienced could help you better;

but for a good start;) :

- you can use unmanaged objects in your managed class, even as members, e.g.
Expand|Select|Wrap|Line Numbers
  1. public ref class Example
  2. {
  3.   public:
  4.      UnmanagedClass* m_member; // here it's important to use a pointer, otherwise the code won't compile
  5. };
  6.  
- as for using return values from unmanaged, check marshaling:
http://msdn2.microsoft.com/en-us/library/system.runtime.interopservices.marshal.aspx

...and examples you asked:

Say I have a form and a button on it. I want to call a perticular function form the unmanaged code when the button is clicked. How do I do that?
Expand|Select|Wrap|Line Numbers
  1. private: System::Void button1_Click(/* args */)
  2. {
  3.    UnmanClass unman();
  4.    unman.someFunction();
  5.    (...)
  6. }
  7.  
Or say when the button is clicked and if at all, I am able to call the function which is returning, say a array. How do I get the values of the elements in the array populaed into a ListBox?
Expand|Select|Wrap|Line Numbers
  1. (...)
  2. int[] returned = unman.getArray(length);
  3. lstBox->Items->Clear(); // assuming you have a lstBox member of type ListBox^
  4. for(int i=0; i< length; i++)
  5. {
  6.   lstBox->Items->Add(returned[i]); // for simple types (like int) - you don't have to convert them from unmanaged to managed, for other check the marshaling
  7. }
  8. (...)
  9.  
in the second example I didn't use std::string or char* (which is more logical for a listbox;) - to see how to convert string to System::String and back, check here:
http://www.thescripts.com/forum/thread281603.html
or here:
http://support.microsoft.com/kb/311259

and last but not least, in case of c++/cli syntax issues, check here, quite a good tutorial:
http://www.functionx.com/cppcli/index.htm

I hope I was at least a little helpful;)

M.
Mar 6 '08 #2
querry
45
Thanks misza,

I will try that out. Thanks a lot.
Mar 7 '08 #3

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

Similar topics

8
by: noid droid | last post by:
Hi. I posted yesterday asking if C# lived up to the hype. Thus far the feedback has been all positive. (Thanks.) Can anyone suggest GOOD books for learning C# and the Visual Studio .NET IDE? ...
13
by: Jason Swett | last post by:
I want to do graphics with C++. Surprisingly, so far nobody has been able to tell me anything helpful. How do I do it? Any input would be greatly appreciated. Jason
3
by: Francis Urquhart | last post by:
I am trying to find the simplest possible way of writing a GUI to run on top of a standard C++ library written in VC++. I would like to avoid MFCs, COM, and if possible .Net wrappers. The goal...
1
by: jm | last post by:
Curious, I have used c++, console wise, always been too overwhelmed with it in Windows. Is it "easier" to use in a managed version? Not near as much code out there for the managed version, except...
1
by: Omid Hodjati | last post by:
Hi All, I have an old unmanaged code written in C++ 6.0. This is a time critcal, CPU bound application. I have deciede migrate this application to managed world and VC++ 7.0. The first step was...
1
by: S Wheeler | last post by:
This may have been previously addressed, if so sorry... I am trying to create a serialization library that will be used from unmanaged vc++. I have working vc++ managed code that serializes and...
5
by: Andy | last post by:
I'm having trouble accessing an unmanaged long from a managed class in VC++.NET When I do, the contents of the variable seem to be mangled. If I access the same variable byte-by-byte, I get the...
5
by: achutha.sridhar | last post by:
I've a pretty basic question on managed code. I read through couple of.net documentation, and reached a state where I know that managed code would be run by the .Net run time and it has so and so...
3
by: Klaus | last post by:
Hi, I have an existing VC 6 MFC application which communicates asynchronly with a VC 2005 managed code dll. I use an unmanaged base class with virtual functions to access methods in the MFC...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.