Click here to Skip to main content
16,017,638 members
Home / Discussions / C#
   

C#

 
GeneralRe: COM/C# datatype mismatch Pin
KingTermite2-Feb-04 11:40
KingTermite2-Feb-04 11:40 
GeneralRe: COM/C# datatype mismatch Pin
Heath Stewart2-Feb-04 11:49
protectorHeath Stewart2-Feb-04 11:49 
GeneralRe: COM/C# datatype mismatch Pin
KingTermite3-Feb-04 3:24
KingTermite3-Feb-04 3:24 
GeneralRe: COM/C# datatype mismatch Pin
Heath Stewart3-Feb-04 3:44
protectorHeath Stewart3-Feb-04 3:44 
GeneralRe: COM/C# datatype mismatch Pin
KingTermite3-Feb-04 4:04
KingTermite3-Feb-04 4:04 
GeneralRe: COM/C# datatype mismatch Pin
Heath Stewart3-Feb-04 4:26
protectorHeath Stewart3-Feb-04 4:26 
GeneralRe: COM/C# datatype mismatch Pin
KingTermite3-Feb-04 4:40
KingTermite3-Feb-04 4:40 
GeneralRe: COM/C# datatype mismatch Pin
KingTermite4-Feb-04 7:28
KingTermite4-Feb-04 7:28 
Ok...I got it (what a pain)! I want to post the answer here for posterity in case somebody else has a similar problem in the future. For the record, I found the answer in a book a co-worker lent me (COM and .NET Interoperability by Andrew Troelsen).


The VB function signature:
<code>Public Function MyFunction(varNames() As String) As String()
showed up as this in the assembly like this:

.method public hidebysig newslot virtual 
instance string[] 
marshal( safearray bstr) 
MyFunction([in][out] string[]& marshal( safearray bstr) varNames) runtime managed internalcall
{
.custom instance void [mscorlib]System.Runtime.InteropServices.DispIdAttribute::.ctor(int32) = ( 01 00 15 00 03 60 00 00 ) // .....`..
.override COMInterface._COMClass::MyFunction 
} // end of method COMClass::MyFunction


The problem was this assembly (and intellisense) was telling it it had to be a safearray and apparently it just wouldn't take a string[]! Not even if it was instantiated on initializaation like:
string[] varNames = new string[] {"One", "Two" };


The intellisense was telling me it had to be a "System.Array", not a string[]!

What needs to be done is not a "cast", but intantiating a System.Array and set it equal to the string array that was initialized and then pass in the ref to that array.

This was the way to get it working was:
COMInterface.COMObj oCOMObject = new COMInterface.COMObj();
			
string[] sNames = new string[] { "ProjectName" }; // 1 element array
System.Array oTemp = sNames;
string[] sValues = new string[1];
System.Array oTempVals = sValues;
oTempVals = oCOMObject.TheCOMFunction( ref oTemp );


It wasn't intuitive....but now, in retrospect, it makes sense. Apparently you have to use the "System.Array" type for the "safearray" that it expects in the assembly, and since it doens't like you to cast it from string[] to System.Array, you have to just create an instance and set it equal.


There are only 10 types of people in this world....those that understand binary, and those that do not.
GeneralCalling a .NET Component from a COM Component Pin
Shahin772-Feb-04 9:11
Shahin772-Feb-04 9:11 
GeneralRe: Calling a .NET Component from a COM Component Pin
Heath Stewart2-Feb-04 9:57
protectorHeath Stewart2-Feb-04 9:57 
GeneralRe: Calling a .NET Component from a COM Component Pin
Shahin772-Feb-04 11:12
Shahin772-Feb-04 11:12 
GeneralRe: Calling a .NET Component from a COM Component Pin
Heath Stewart2-Feb-04 11:45
protectorHeath Stewart2-Feb-04 11:45 
GeneralUrgent help (Calling a .NET Component from a COM Component) Pin
Shahin773-Feb-04 4:16
Shahin773-Feb-04 4:16 
GeneralRe: Urgent help (Calling a .NET Component from a COM Component) Pin
Heath Stewart3-Feb-04 6:30
protectorHeath Stewart3-Feb-04 6:30 
GeneralRe: Urgent help (Calling a .NET Component from a COM Component) Pin
Shahin774-Feb-04 6:48
Shahin774-Feb-04 6:48 
GeneralRe: Urgent help (Calling a .NET Component from a COM Component) Pin
Heath Stewart4-Feb-04 7:04
protectorHeath Stewart4-Feb-04 7:04 
GeneralRe: Urgent help (Calling a .NET Component from a COM Component) Pin
Shahin774-Feb-04 7:42
Shahin774-Feb-04 7:42 
GeneralRe: Urgent help (Calling a .NET Component from a COM Component) Pin
Heath Stewart4-Feb-04 8:41
protectorHeath Stewart4-Feb-04 8:41 
GeneralRe: Calling a .NET Component from a COM Component Pin
KingTermite2-Feb-04 10:14
KingTermite2-Feb-04 10:14 
GeneralRe: Calling a .NET Component from a COM Component Pin
Heath Stewart3-Feb-04 5:56
protectorHeath Stewart3-Feb-04 5:56 
GeneralIDocHostUIHandler, FilterDataObject Pin
s.keller2-Feb-04 9:05
s.keller2-Feb-04 9:05 
GeneralRe: IDocHostUIHandler, FilterDataObject Pin
Nick Parker2-Feb-04 9:15
protectorNick Parker2-Feb-04 9:15 
GeneralRe: IDocHostUIHandler, FilterDataObject Pin
s.keller2-Feb-04 9:21
s.keller2-Feb-04 9:21 
GeneralRe: IDocHostUIHandler, FilterDataObject Pin
Heath Stewart2-Feb-04 9:49
protectorHeath Stewart2-Feb-04 9:49 
GeneralRe: IDocHostUIHandler, FilterDataObject Pin
s.keller2-Feb-04 9:55
s.keller2-Feb-04 9:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.