Custom formula with C++ and a .NET DLL?
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Printer Friendly Page
- Mark as New
- Subscribe to RSS Feed
- Permalink
Hi there,
I'm trying to switch over some custom functions from SQL (which used C#.NET) to Alteryx.
I have the basics setup so the C++ program can use the .NET DLL. However, when I try to use it with Alteryx, it doesn't seem to work.
Is there some way I can debug it better? It just keeps giving me "An unknown error occurred in II_INIT" in the formula.
Thank you, Sam
- Labels:
- Custom Formula Function
- Mark as New
- Subscribe to RSS Feed
- Permalink
Cross between unmanaged C++ (which Alteryx runs) and C# is difficult. There are a couple of options:
1. Rewrite the custom function code in C++ and keep it all unmanaged
2. Use the deprecated C# custom tool SDK (its within APIs\SampleCode\CustomDotNetTools)
3. Look at using DllExport in C# (https://www.nuget.org/packages/DllExport/) to make the C# function exposed to unmanaged C++
2 has a limited lifespan as deprecated and due to be retired at end of 2021.
If you can share some code can probably make some more progress
- Mark as New
- Subscribe to RSS Feed
- Permalink
Here's some simple code examples that I've tried:
This is exported as a .NET 4.7.2 DLL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace clsTest
{
public class tester
{
int number;
public tester(int numb)
{
number = numb;
}
public int testIt()
{
return number * 10;
}
}
}
This is the custom function code
#include "AlteryxFunction.h"
#using <C:\Users\00007341\source\repos\alteryxReins\x64\Debug\clsTest.dll>
using namespace clsTest;
extern "C" long _declspec(dllexport) _stdcall getReinsPerc(int nNumArgs, FormulaAddInData * pArgs, FormulaAddInData * pReturnValue)
{
pReturnValue->nVarType = nVarType_DOUBLE;
clsTest::tester^ num = gcnew clsTest::tester(10);
int testedNumb = num->testIt();
pReturnValue->isNull = 0;
pReturnValue->dVal = testedNumb;
return 1;
}
If I do something even simpler, like this:
#include "AlteryxFunction.h"
#using <C:\Users\00007341\source\repos\alteryxReins\x64\Debug\clsTest.dll>
using namespace clsTest;
extern "C" long _declspec(dllexport) _stdcall getReinsPerc(int nNumArgs, FormulaAddInData * pArgs, FormulaAddInData * pReturnValue)
{
pReturnValue->nVarType = nVarType_DOUBLE;
pReturnValue->isNull = 0;
pReturnValue->dVal = 5;
return 1;
}
It works just fine.
I'll look into your suggestions, thank you!
- Mark as New
- Subscribe to RSS Feed
- Permalink
Unfortunately gcnew requires CLR C++ which can't be used within the custom formula stuff. I'll have a play this evening and see what I can come up with for you.