473,387 Members | 1,573 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Object To Variant

I am interfacing to a non .NET app and one of the params is of type variant.
In C# it is asking for an object. I went down that path with no luck. I ran
across using "marshal as" to convert an object to a variant. I cannot see
how to do this? I have 10 params to send a method by reference as type
variant. Is there an easy way to do this? Any help is greatly apprecieated.

Thanks;
Bob;
Nov 13 '05 #1
6 26004
Not so sure about this...but have you tried:
bool retVal = MethodYoureCalling([ MarshalAs( UnmanagedType.AsAny )]object
parameter1,[ MarshalAs( UnmanagedType.AsAny )]object parameter1);

"Bob Allen" <Bo*@324pm.com> wrote in message
news:%2*****************@TK2MSFTNGP10.phx.gbl...
I am interfacing to a non .NET app and one of the params is of type variant. In C# it is asking for an object. I went down that path with no luck. I ran across using "marshal as" to convert an object to a variant. I cannot see
how to do this? I have 10 params to send a method by reference as type
variant. Is there an easy way to do this? Any help is greatly apprecieated.
Thanks;
Bob;

Nov 13 '05 #2
I have and with no luck. I am using the following method. Which is close to
the same....thanks for post.
[MarshalAs(UnmanagedType.AsAny)]
private object primaryFieldResultDataSA;

private void MyMethod()

{

int i = callme(ref primaryFieldResultDataSA);

}

"Jenny K" <je*****@hotmail.com> wrote in message
news:OI**************@TK2MSFTNGP10.phx.gbl...
Not so sure about this...but have you tried:
bool retVal = MethodYoureCalling([ MarshalAs( UnmanagedType.AsAny )]object
parameter1,[ MarshalAs( UnmanagedType.AsAny )]object parameter1);

"Bob Allen" <Bo*@324pm.com> wrote in message
news:%2*****************@TK2MSFTNGP10.phx.gbl...
I am interfacing to a non .NET app and one of the params is of type

variant.
In C# it is asking for an object. I went down that path with no luck. I

ran
across using "marshal as" to convert an object to a variant. I cannot see how to do this? I have 10 params to send a method by reference as type
variant. Is there an easy way to do this? Any help is greatly

apprecieated.

Thanks;
Bob;


Nov 13 '05 #3
Bob,
I am interfacing to a non .NET app and one of the params is of type variant.
In C# it is asking for an object. I went down that path with no luck.


So what happened? Did you get an error? What kind of Variant does the
app expect, and what do you pass to it?

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 13 '05 #4
Do you know what language the thing that needs the variants is in?
Nov 13 '05 #5
I have tried this a couple different ways. Here are some of the ways is set
it up. And my example is not true to form. I will expain.
1st Way: [MarshalAs(UnmanagedType.AsAny)] object fieldIdSA = new int [8];
2nd Way: object fieldIdSA = new int [8];

The method calls for a ref to the object. so my example should be
mymethod(ref fieldIdSA);

In the example project it works in VB6. If you use the type as Variant. But
if i try to do the same in .NET either C# or VB it does not work???? This
one is stumping me....

"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:eS*************@TK2MSFTNGP11.phx.gbl...
Bob,
I am trying to write this in C# not VB but i tried it as a last resort to
see if i could at least get results.
This is an error generated by the control. I am getting a return code of
ERROR_WRONG_PARAM_TYPE Type mismatch in parameter
this is obvious not much to go on.


When moving the code from VB6 to VB.NET or C#, did you remember to
change the array type from Long to Integer/int? I'd expect this to
work

object MFPrimaryFieldScores = new int[8];
object MFPrimaryResultData = new string[8];
int ret = mymethod(MFPrimaryFieldScores,MFPrimaryResultData) ;

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.

Nov 13 '05 #6
Bob,
1st Way: [MarshalAs(UnmanagedType.AsAny)] object fieldIdSA = new int [8];
You can't attribute individual variable declarations so that shouldn't
even compile.

2nd Way: object fieldIdSA = new int [8];


That looks like it should work, it's the equivalent of the VB code you
posted before. It's hard to say why it doesn't without seeing more of
the code and having the COM object to play with.

Do you know if the COM object was implemented in MFC?

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 13 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Raoul | last post by:
I wrote a COM server object in C++ a few months ago. I can use it from Visual Basic, Visual C++, S-Plus and a number of other scripting environments. What I can't do is use it with my FAVOURITE...
1
by: C. N. Sridhar | last post by:
Hi, I'm writing a wrapper to a win32 dll in C#. I need to call a method in DLL which has a Variant type reference parameter. How to marshal variant type from win32 (unmanaged code) to C#...
0
by: Russ Gadagno | last post by:
Hi, I’m trying to use net remoteing with Com+. I created a wrapper for the com object. I can call the com object from my c# client and an able to get return type of strings and int’s. One of...
2
by: Ken Layton | last post by:
Attempting to pass a VBScript Array of Bytes to a C# Managed COM object has resulted in some very undesirable and strange behavior. When definining a method in my C# COM class as "void Write(byte...
3
by: tigrrgrr42 | last post by:
I am working(vb.net03and05) with word documents stored in a sql db and I am currently bringing them from a byte array into a temp file to pop into word and make word do its thing as a com object. ...
19
by: Alan Carpenter | last post by:
Access 8 on Win98 and WinXP I'm having trouble with wildcards in the .Filename property of the FileSearch Object giving different results on win98 and XP. I've been successfully using...
4
by: buzzluck68 | last post by:
Hello, I am having trouble upgrading my VB apps to .net. When i started at my company there was a dll created here in vb6, and i need to use that dll for many functions that would take too much...
4
by: =?Utf-8?B?cGJsYWNrYnVybg==?= | last post by:
Summary Getting the error message Run time error 424 Object Required when attempting to assign a value to a C# COM visible property of type object. I have created a COM visible class as below ...
0
by: dileepsree | last post by:
My aim is :- Pass C# object as a parameter of unmanaged Dll(vc++ 6.0) method . with in the unmaaged dll methedod construct similar C++ class instance . vice versa from dll method argument...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.