K
KD Park
Guest
I have a question.
I'm developing C# COM client and C++ COM server.
I created a function that returns SafeArray with a custom structure declared in C++. When I call this function in C# COM client as below, a TypeLoadException occurs.
----------- .idl file (C++) ---------------
interface ICustomInterface : IDispatch
{
HRESULT GetSafeArray([out, retval]SAFEARRAY(CustomStruct)* pStructArray);
};
----------- C# client ---------------
try
{
ICustomInterface custom = new CustomInterface();
Array arr = custom.GetSafeArray(); // TypeLoadException
if (arr != null)
{
}
}
catch (TypeLoadException ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
So I tried several ways to solve this problem, and I found out that Exception does not occur when I try to do the following.
----------- C# client ---------------
try
{
ICustomInterface custom = new CustomInterface();
CustomStruct customStruct = new CustomStruct(); // TypeLoadException is not occur with this line of code.
Array arr = custom.GetSafeArray(); // TypeLoadException
if (arr != null)
{
}
}
catch (TypeLoadException ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
The only difference is that declared the custom structure before calling the interface.
I really want to know why this is happening.
Thanks in advance.
Continue reading...
I'm developing C# COM client and C++ COM server.
I created a function that returns SafeArray with a custom structure declared in C++. When I call this function in C# COM client as below, a TypeLoadException occurs.
----------- .idl file (C++) ---------------
interface ICustomInterface : IDispatch
{
HRESULT GetSafeArray([out, retval]SAFEARRAY(CustomStruct)* pStructArray);
};
----------- C# client ---------------
try
{
ICustomInterface custom = new CustomInterface();
Array arr = custom.GetSafeArray(); // TypeLoadException
if (arr != null)
{
}
}
catch (TypeLoadException ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
So I tried several ways to solve this problem, and I found out that Exception does not occur when I try to do the following.
----------- C# client ---------------
try
{
ICustomInterface custom = new CustomInterface();
CustomStruct customStruct = new CustomStruct(); // TypeLoadException is not occur with this line of code.
Array arr = custom.GetSafeArray(); // TypeLoadException
if (arr != null)
{
}
}
catch (TypeLoadException ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
The only difference is that declared the custom structure before calling the interface.
I really want to know why this is happening.
Thanks in advance.
Continue reading...