G
Guest
I'm using VS2005 to write a C++ dll to use some Win32 APIs, and I'm calling
the dll from a C# program. I've created the following C# class that I'm using
to create an array to pass to the dll. The C# program creates the array with
more than one dimension, but the C++ dll only sees the first dimension. Here
is the class that I used to create the array (it will eventually contain much
more than a string):
namespace TestObjectClass
{
public class TestObject
{
public TestObject(string Name)
{
name = Name;
}
private string name;
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
}
}
This is the C# caller:
....
using System.Runtime.InteropServices;
using TestObjectClass;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
TestObject[] testObjectArray = new TestObject[4];
testObjectArray[0] = new TestObject("Name0");
testObjectArray[1] = new TestObject("Name1");
testObjectArray[2] = new TestObject("Name2");
testObjectArray[3] = new TestObject("Name3");
// call C++ dll here
processTestObjectArrayClass.ProcessArray(this.Handle,
testObjectArray);
}
}
public class processTestObjectArrayClass
{
[DllImport(@"..\..\..\Debug\TestArrayDll.dll")]
public static extern int ProcessArray(IntPtr handle, TestObject[]
testObjectArray);
}
}
And here is the C++ dll:
....
#using <TestObjectClass.dll>
....
using namespace TestObjectClass;
....
int __clrcall ProcessArray(HWND hWnd, array<TestObject^>^ testObjectArray)
{
for (int i = 0; i < testObjectArray->Length; i++)
{
pin_ptr<const wchar_t> name =
PtrToStringChars(testObjectArray->Name->ToString());
::MessageBox(hWnd, name, L"Test Object Array", MB_OK);
}
return 0;
}
I created the dll to use shared MFC.
What am I doing to cause only the first dimension in the array to be seen?
Thanks,
David
the dll from a C# program. I've created the following C# class that I'm using
to create an array to pass to the dll. The C# program creates the array with
more than one dimension, but the C++ dll only sees the first dimension. Here
is the class that I used to create the array (it will eventually contain much
more than a string):
namespace TestObjectClass
{
public class TestObject
{
public TestObject(string Name)
{
name = Name;
}
private string name;
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
}
}
This is the C# caller:
....
using System.Runtime.InteropServices;
using TestObjectClass;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
TestObject[] testObjectArray = new TestObject[4];
testObjectArray[0] = new TestObject("Name0");
testObjectArray[1] = new TestObject("Name1");
testObjectArray[2] = new TestObject("Name2");
testObjectArray[3] = new TestObject("Name3");
// call C++ dll here
processTestObjectArrayClass.ProcessArray(this.Handle,
testObjectArray);
}
}
public class processTestObjectArrayClass
{
[DllImport(@"..\..\..\Debug\TestArrayDll.dll")]
public static extern int ProcessArray(IntPtr handle, TestObject[]
testObjectArray);
}
}
And here is the C++ dll:
....
#using <TestObjectClass.dll>
....
using namespace TestObjectClass;
....
int __clrcall ProcessArray(HWND hWnd, array<TestObject^>^ testObjectArray)
{
for (int i = 0; i < testObjectArray->Length; i++)
{
pin_ptr<const wchar_t> name =
PtrToStringChars(testObjectArray->Name->ToString());
::MessageBox(hWnd, name, L"Test Object Array", MB_OK);
}
return 0;
}
I created the dll to use shared MFC.
What am I doing to cause only the first dimension in the array to be seen?
Thanks,
David