# Managed C++ examples

**URL:** https://www.finalbuilder.com/forums/t/managed-c-examples/514
**Category:** Discussion
**Created:** [June 28, 2007, 5:07am UTC](https://www.finalbuilder.com/forums/t/managed-c-examples/514 "2007-06-28T05:07:19Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![deleted\_user](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/deleted_user/32/937_2.png) [@deleted\_user](https://www.finalbuilder.com/forums/u/deleted_user)
#### Post date: [June 28, 2007, 5:07am UTC](https://www.finalbuilder.com/forums/t/managed-c-examples/514/1 "2007-06-28T05:07:19Z")

</div>

&nbsp;

Hi,

I'm trying to write a custom action .dll using managed C++ in Microsoft Visual 2005.

Are there examples of this ?

All I'm after is stub to show the parameter passing mechanism.

Thanks,  
Steve.

&nbsp;

&nbsp;

&nbsp;

---

<div class="post-metadata">

### Author: ![Vincent](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/vincent/32/938_2.png) [@Vincent](https://www.finalbuilder.com/forums/u/Vincent)
#### Post date: [June 29, 2007, 12:48pm UTC](https://www.finalbuilder.com/forums/t/managed-c-examples/514/2 "2007-06-29T12:48:59Z")

</div>

Hi Steve

&nbsp;

I have to admit I don't think we have tried to write actions using Managed C++ before. This is my first attempt with Managed C++, I'm kinda shocked at how little the VS IDE does for you compared to the other languages it supports!

I got this to compile, but haven't tested it yet :

&nbsp;

// CPPTest.h  
  
#pragma once  
  
using namespace System;  
using namespace FB60CustomActionInterfaces;  
  
namespace CPPTest {  
  
&nbsp;&nbsp;&nbsp; public ref class Class1 : IFBCustomAction&nbsp;&nbsp;&nbsp;   
&nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // TODO: Add your methods for this class here.  
&nbsp;&nbsp;&nbsp; public: virtual System::Void AbortAction(FB60CustomActionInterfaces::IFBCustomActionExecuteContext^ Context)  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;   
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; };  
&nbsp;&nbsp;&nbsp; public: virtual System::Boolean OnExecute(FB60CustomActionInterfaces::IFBCustomActionExecuteContext^ Context)  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return false;&nbsp;&nbsp;&nbsp;   
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; };  
&nbsp;&nbsp;&nbsp; public: virtual System::Boolean OnValidate(FB60CustomActionInterfaces::IFBCustomActionValidateContext^ Context)  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return false;  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; };  
&nbsp;&nbsp;&nbsp; public: virtual System::Boolean SupportsAbort()  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return false;  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; };  
&nbsp;&nbsp;&nbsp; };  
}

I will try to test this later today if time permits (end of financial year stuff to deal with today).

&nbsp;

&nbsp;

&nbsp;

&nbsp;

---

<div class="post-metadata">

### Author: ![deleted\_user](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/deleted_user/32/937_2.png) [@deleted\_user](https://www.finalbuilder.com/forums/u/deleted_user)
#### Post date: [June 29, 2007, 1:16am UTC](https://www.finalbuilder.com/forums/t/managed-c-examples/514/3 "2007-06-29T01:16:34Z")

</div>

Thanks Vincent.

&nbsp;

I finally managed to get there in the end using "code by permutation", although I've now hit the next brickwall!!!

I'm trying to return a value from my managed C++ back to finalbuilder.

In my managed C++ i've used the line

&nbsp;&nbsp;&nbsp; context-\>SetVariable(context-\>Properties-\>PropertyAsString::get("ReturnString"), string1);

to set the property "ReturnString" to value of string1.

&nbsp;

In ActionStudio, I've included a property "ReturnString" and a property page with a text box that uses

"bind to" ReturnString.

When calling this custom action, I insert a finalbuilder variable "%returnString%" into the above textBox,

but when I run the program, nothing gets returned.

&nbsp;

Any sugguestions?

&nbsp;

thanks, Steve

&nbsp;

&nbsp;

&nbsp;

---

<div class="post-metadata">

### Author: ![Vincent](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/vincent/32/938_2.png) [@Vincent](https://www.finalbuilder.com/forums/u/Vincent)
#### Post date: [June 30, 2007, 1:01am UTC](https://www.finalbuilder.com/forums/t/managed-c-examples/514/4 "2007-06-30T01:01:44Z")

</div>

Hi Steve

Try splitting up the statement so we can see where it is going wrong :

System::String^ variablename = context-\>Properties-\>PropertyAsString::get("ReturnString");

context-SendLogMessage(variablename);

context-\>SetVariable(variablename, string1);

Then we can see if the variable name is ok.

Other than that, you can send you VC project and action package to support and I will take a look at it on monday and see if I can debug it and figure out what is going wrong.

&nbsp;

---

<div class="post-metadata">

### Author: ![deleted\_user](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/deleted_user/32/937_2.png) [@deleted\_user](https://www.finalbuilder.com/forums/u/deleted_user)
#### Post date: [July 2, 2007, 3:22am UTC](https://www.finalbuilder.com/forums/t/managed-c-examples/514/5 "2007-07-02T03:22:20Z")

</div>

Hi Vincent,

I tried that, and in Visual, it seems to have picked up the correct variable name from the property,

but when I pass that value through, it doesn't appear to be making it into finalbuilder

ie. a watch on the variable remains the same.

&nbsp;

I've sent a copy of the Visual solution and action studio action to support.

&nbsp;

Thanks,  
Stephen.

&nbsp;

---

<div class="post-metadata">

### Author: ![deleted\_user](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/deleted_user/32/937_2.png) [@deleted\_user](https://www.finalbuilder.com/forums/u/deleted_user)
#### Post date: [July 2, 2007, 5:01am UTC](https://www.finalbuilder.com/forums/t/managed-c-examples/514/6 "2007-07-02T05:01:59Z")

</div>

Ok,

I think I've found the problem...

In action studio, I used a TextEdit box for the return value as opposed to a VariablesComboBox.

This seems to have fixed the problem and I can now pass the value through.

&nbsp;

As an aside, am I able to do it using a TextEdit box ? From memory, I thought some of the native actions allowed you to specify variables directly into a TextEdit as opposed to the VariablesComboBox ?

Thanks for the help,

Steve.

&nbsp;

&nbsp;

&nbsp;

---

<div class="post-metadata">

### Author: ![Vincent](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/vincent/32/938_2.png) [@Vincent](https://www.finalbuilder.com/forums/u/Vincent)
#### Post date: [July 2, 2007, 11:50am UTC](https://www.finalbuilder.com/forums/t/managed-c-examples/514/7 "2007-07-02T11:50:26Z")

</div>

Hi Steve   
  
 I haven’t looked at your project yet, but my guess would be that you are specifying the variable name in the textbox with % symbols, which you shouldn’t do when dealing with variable names rather than variable references.
