Author Topic: Using C++ instead  (Read 8425 times)

Corneel

  • Guest
Using C++ instead
« on: May 02, 2018, 06:23:13 PM »
If I wanted to use C++ instead of C# - how would I go about doing that? I will be using Visual Studio C++.

Thanks.
Corneel.

Exergist

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 405
  • Ride the lightning
Re: Using C++ instead
« Reply #1 on: May 03, 2018, 09:15:15 AM »
That is an interesting question. I don't think you can directly, but Gary would have to weigh in on that. I only recently started to lightly dabble in C++, and here is an example of passing a string from a VA C# inline function to a 32-bit C++ library (bear in mind that C++ is quite foreign to me):

VA C# Inline Function
Referenced Assemblies: System.dll
Code: [Select]
using System;
using System.Text;
using System.Runtime.InteropServices;

public class VAInline
{
const string path = @"YourPathHere\MyLibary.dll"; // x86 library

public void main()
{
string str = "Hello World!";
StringBuilder sb = new StringBuilder(str, str.Length);
SendStringToPapyrus(sb);
}

[DllImport(path, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
extern static void SendStringToCpp([MarshalAs(UnmanagedType.LPWStr)] StringBuilder str);
}

// References:
// http://www.cplusplus.com/doc/tutorial/files/
// https://manski.net/2012/05/pinvoke-tutorial-basics-part-1/
// https://social.msdn.microsoft.com/Forums/vstudio/en-US/0e808314-8888-4320-af94-dd0ffbb8ecfd/passing-c-stringbuilder-array-to-c-dll?forum=csharpgeneral

C++ Header (MyClass.h)
Code: [Select]
#pragma once

extern "C"
{
        __declspec(dllexport) void SendStringToCpp(wchar_t* strIn);
}

C++ Declaration File (MyClass.cpp)
Code: [Select]
#pragma once

#include "MyClass.h"
#include <fstream>
#include <string>

using namespace std;

// Function for outputting a string to a text file
__declspec(dllexport) void SendStringToCpp(wchar_t* strIn)
{
wstring ws(strIn);
string MyString(ws.begin(), ws.end());
string FileName = "my_file.txt";
ofstream myfile;
myfile.open(FileName);
myfile << MyString;
myfile.close();
}

This will output the C# 'str' of "Hello World!" to a text file in VA's root directory. You can use this methodology to pass strings to your C++ library and with some additional massaging also pass other types.

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2827
Re: Using C++ instead
« Reply #2 on: May 03, 2018, 10:14:30 AM »
I haven't touched C++ in a long, long time.  If it can compile down into .net assembly with the properties and methods in the examples it should work.

HansNel

  • Guest
Re: Using C++ instead
« Reply #3 on: July 04, 2018, 12:33:12 PM »
I don't suppose one can use Visual Studio Visual Basic in VA?
Many programs in the past used VB Script...notibly MS Office. (Yes, I know ;-) )
EDIT: Excellent! I just now noticed that VA DOES support VB! Under "Other/Advanced/Execute an Inline Function"
VA is truly impressive!
« Last Edit: July 04, 2018, 01:54:38 PM by HansNel »

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Using C++ instead
« Reply #4 on: July 04, 2018, 01:53:17 PM »
Yes and no.

If you're referring to VB.net, that can be utilized for inline functions and plugins, however both are intended to add functionality VoiceAttack doesn't already provide natively, not as an alternative to native VoiceAttack actions.

Because of this, you can't directly execute VoiceAttack actions from inline functions or plugins; You can manipulate variables or execute whole commands, however.

Exergist

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 405
  • Ride the lightning
Re: Using C++ instead
« Reply #5 on: July 05, 2018, 10:47:58 AM »
There are certainly ways to use C# or vb.net inline functions to "simplify" your command's action list. Often an inline function can more elegantly achieve the same end result as VA can natively, but as Pfeil commented it usually is best to learn about VA's base functionality (again, the manual is your friend here) and work from there.