I appreciate that advice Cypher, yeah Option 1 does sound slightly cleaner, rather than the brute force approach. I'll keep hunting for some other solutions, and post back if I actually find anything of interest (though my late night googling did not yield anything promising).
EDIT:
Bah I'm really too lazy, Option 1 works like a charm I'll leave it as it is.
EDIT:
Oh for those that want the C/P sample Export/Import Code for inprocess C++/C# library calling:
C++ DLL:
Code:
//Just a random function I made to accept a list of lines and render them
//Sorry no code on rendering lines here, plenty of other forum topics cover this.
extern "C" {
__declspec(dllexport)void __cdecl DrawLines(IDirect3DDevice9* pDevice, LINEVECTOR lineList[], int lineCount);
}
C# Assembly:
Code:
static class DXDraw
{
//Delegate to handle the exported function signature.
//LINEVECTOR is a custom struct that describes a line (start/end vertex and colour)
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void DrawLinesDelegate(IntPtr pDevice, [MarshalAs(UnmanagedType.LPArray)] LINEVECTOR[] lineList, int lineCount);
//Holds the marshaled function
static DrawLinesDelegate DrawLines;
//Constructor
static DXDraw()
{
//Get Reference to our inprocess assembly location
//I keep all my libraries/assemblies in the same folder for ease of updating
string appDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string filename = Path.Combine(appDir, "BootstrapLib.dll");
//Load our Library
IntPtr dllPtr = NativeMethods.LoadLibrary(filename);
if (dllPtr== IntPtr.Zero)
{
throw new NullReferenceException("LoadLibrary Failed");
}
//Obtain a pointer to our function
IntPtr funcPtr= NativeMethods.GetProcAddress(dllPtr, "DrawLines");
if (funcPtr== IntPtr.Zero)
{
throw new NullReferenceException("DrawLines Failed");
}
//Marshal the address of the function to the delegate above this constructor
DrawLines= (DrawLinesDelegate)Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(DrawLinesDelegate));
//Drop reference count by 1....just a note BootstrapLib.dll is actually loaded previously to begin the .Net Runtime.
NativeMethods.FreeLibrary(dllPtr);
}
//Just a stub for testing in my pulse
static void test(IntPtr pDevice)
{
ColorARGB green = new ColorARGB();
green.Alpha = 100;
green.Red = 0;
green.Green = 255;
green.Blue = 0;
float startZ = 94.55733f;
LINEVECTOR[] lineList = new LINEVECTOR[9];
//Setup line list.
for (int i = 0; i < 9; i++)
{
lineList[i].X = -140.43083f;
lineList[i].Y = 1865.19995f;
lineList[i].Z = startZ;
lineList[i].X2 = -140.43083f;
lineList[i].Y2 = 1865.19995f;
lineList[i].Z2 = startZ+10;
lineList[i].Color = green;
startZ += 10;
}
//Yay vertical lines!
DrawLines(pDevice, lineList, 9);
}