TheSwamp
Code Red => .NET => Topic started by: dukesys on October 10, 2006, 06:09:12 PM
-
Hello all,
I am working on a .NET project that needs to call out to a function in a VB6 DLL. When it makes the call AutoCAD throws a wobbly with the following error.
Unable to cast object of type 'System.Object[]' to 'FileTools.clsMaskSpec[]'
I know the routine in the DLL works fine as I can call it ok from VB6, so I think it must me some sort of .NET issue.
The function takes the following form.
getMatchingstrings(byref specArray as system.Array, byref retval as System.Array)
The function takes two arrays as input, the second array is modified to return the result. The function in the DLL has no defined return. eg.
Function getMatchingStrings(spec() as clsMaskSpec, retVal() as string)
Any help would be appreciated.
Regards
Martin.
-
Hi Martin, welcome aboard!
The first place I would look is at 'DllImport', I'm not up with vb (especially spec(), what is that?) but you will need to marshal your types across the process boundaries from .net to unmanaged and back. If you work out how to do this you should be ok.
hth.
-
Hi Mick,
thank you for your response, not sure how to proceed from here but will do some further research.
Cheers,
Martin.
Hi Martin, welcome aboard!
The first place I would look is at 'DllImport', I'm not up with vb (especially spec(), what is that?) but you will need to marshal your types across the process boundaries from .net to unmanaged and back. If you work out how to do this you should be ok.
hth.
-
Sorry I couldn't be of anymore help.
Just looking at your code though -
The function takes the following form.
getMatchingstrings(byref specArray as system.Array, byref retval as System.Array)
both params are arrays and as such are simply a pointer to the start of the array itself, perhaps you can try something like
[DllImport("yourDllname.dll", CallingConvention=CallingConvention.Cdecl)]
private static extern void getMatchingstrings(System.IntPtr, System.IntPtr);
// then use it like:
getMatchingstrings(spec().unmanagedObject,retval.unmanagedObject);
..or something like that anyways.
hth,
Mick.
-
getMatchingstrings(byref specArray as system.Array, byref retval as System.Array)
Maybe it's just the VB stuff which I'm not used too, but that just looks wrong.
If I was to literally do that in C# it would look like this:
getMatchStrings(object[] specArray, object[] retVal)
However, what I think you want is this:
getMatchStrings(FileTools.clsMaskSpec[] specArray, string[] retval)
...or the VB.Not :) equivalent of somehing like that.
-
Hello,
Thank you for all your help on this topic, I have however decided to bight the bullet and convert the VB6 DLL into .NET. Not really what I had hoped to do but probably the best thing to do.
cheers
Martin.
-
Told you :-P :-D
-
[jedihandwave]
/// ...
[/jedihandwave]
:-)