Can a C++ Dll being called from Excel VBA return final output to Excel but also produce a Text/CSV file which may contain results of intermediate calculations.
Also, can a C++ dll return the result as an array.
Any simple code examples would be much appreciated..
Can a C++ Dll being called from Excel VBA return final output to Excel but also produce a Text/CSV file which may contain results of intermediate calculations.
That would depend on the output the DLL is returning, a SOCKET struct would be of very little use to a spreadsheet cell. If you're already working with VB then don't dumb down your application by using a text delimited format, the Application.Excell namespace is much easier to work with then you might think.
Also, can a C++ dll return the result as an array.
for (long int i = 0; i < x; i++)
{
for (long int j = 0; j < x; j++)
{
myVect[j][i] = v[i + j * x];
temp = temp + myVect[j][i];
}
}
Print2DVec(myVect, "My 2D Vector", myfilename, myfilepath);//Function Call to print the input vector to a CSV (test)
return temp; //Return sum of input Vector values
}
}
//Function to Print Vector to a file with i/p filename, label to the same folder as the VS Project
void Print2DVec(std::vector<std::vector<double>>const& myVect, string op_label,
string myfilename, string myfilepath)
{
ofstream output; //define o/p stream
output.open((myfilepath+"\\"+myfilename).c_str(), std::ios_base::app); //string to char conversion
I want to start off by saying that you're going about this in a very odd way, if your interest in this is functional as opposed to academic then I would recommend redesigning your solution from the ground up. This is something we can help with if you can provide the necessary details.
The biggest flaw with your approach here is that Excel locks the files that it works with. From what I gather you're trying to load this DLL into Excel and have it call your function so that the DLL can then write data back to that same file. Excel has ways of accomplishing what you are trying to do, but unfortunately they are no where near as straight forward as this. These methods aren't some kind of magic, and they are all as well documented as you would expect from MSDN (which is very well by the way). However you may not be ready for the learning curve. So I would again encourage you to consider letting us help you redesign your solution.
The purpose is entirely academic. Basically the Excel is calling the DLL to return only one value and that is the sum of all values of the Matrix.
However, there maybe a case when the calculations may not be so simple and may have many intermediate calculations that we may want to review (or not) to validate the final result but not necessarily return to the excel sheet.
For that purpose I was curious if I can produce a text/csv or whatever via a dll being called from vba.