473,324 Members | 2,124 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,324 software developers and data experts.

How to overcome the limitation: Cannot pass 'argument' as ref or out, because ' argument ' is a marshal-by-reference class

It is known that one cannot pass arguments as ref or out in a
marshal-by-reference class. My problem is that I have a C DLL (and C#
wrapper) that I need to isolate in an AppDomain and then I need to interact
with many objects in that DLL and wrapper by reference. (So the classes
inherit from MBRO.) While my app is running, I need to obtain info from
objects in the 2nd app domain frequently/speedily and I need update the GUI;
and I need to pass user actions back to the DLL. I also need to handle
events across the AppDomain boundary. All this sounds fairly standard, I
guess (I'm new to remoting.)

However, the C# wrapper has a lot of methods that use 'out' parameters, and
I can't change this (might as well rewrite the whole app from scratch). So,
my question is, How can I isolate this set of objects in an AppDomain
without throwing all that code away? The methods with ref and out parameters
could be wholly 'bounded' or contained within the new AppDomain. In other
words, these methods are not needed in regard to communicating across the
AppDomain boundary, but are only needed for objects within the new AppDomain
to interact with each other. Any suggestions on how to do this?

On a different but related point, I read in a post from 2001 the following:
" Fields of App-Domain-bound objects must be accessed through accessors.
so for any objects derived from MarshalByRefObject (as is your TreeNode)
you must provide put/get methods (for your color member)."

If I understand that correctly, it means that implementing Properties in
place of certain methods the C# wrapper currently uses for returning values
would help. But that doesn't solve my main ref/out param issue, but it is
interesting. Anyone care to point me to more info on either/both of these
topics?

Dave
Nov 15 '05 #1
2 4692
Hum, complex topic. What you should do IMO, if the objects you need are
created and consumed in your second AppDomain, is to create a proxy object
that you create from your first AppDomain in your second AppDomain using
CreateInstanceAndUnwrap. If this object inherit from MBR, you can then use
it to call methods that will in fact execute in the second application
domain, and you can, in these methods create your objects or get back the
objects from the out and ref parameters of your C dll. It's then just a
matter of getting the value you want back, and put them in a MBV back to
your first AppDomain to prevent any more marshalling.

This is the only way I could figure to get good encapsulation and prevent a
few nifty remoting tricks such as viral dll loading across appdomains :)

--
Sebastien Lambla
http://thetechnologist.is-a-geek.com/blog/
"Mountain Bikn' Guy" <vc@attbi.com> a écrit dans le message de news:
cBRpb.77282$275.206628@attbi_s53...
It is known that one cannot pass arguments as ref or out in a
marshal-by-reference class. My problem is that I have a C DLL (and C#
wrapper) that I need to isolate in an AppDomain and then I need to interact with many objects in that DLL and wrapper by reference. (So the classes
inherit from MBRO.) While my app is running, I need to obtain info from
objects in the 2nd app domain frequently/speedily and I need update the GUI; and I need to pass user actions back to the DLL. I also need to handle
events across the AppDomain boundary. All this sounds fairly standard, I
guess (I'm new to remoting.)

However, the C# wrapper has a lot of methods that use 'out' parameters, and I can't change this (might as well rewrite the whole app from scratch). So, my question is, How can I isolate this set of objects in an AppDomain
without throwing all that code away? The methods with ref and out parameters could be wholly 'bounded' or contained within the new AppDomain. In other
words, these methods are not needed in regard to communicating across the
AppDomain boundary, but are only needed for objects within the new AppDomain to interact with each other. Any suggestions on how to do this?

On a different but related point, I read in a post from 2001 the following: " Fields of App-Domain-bound objects must be accessed through accessors.
so for any objects derived from MarshalByRefObject (as is your TreeNode)
you must provide put/get methods (for your color member)."

If I understand that correctly, it means that implementing Properties in
place of certain methods the C# wrapper currently uses for returning values would help. But that doesn't solve my main ref/out param issue, but it is
interesting. Anyone care to point me to more info on either/both of these
topics?

Dave

Nov 15 '05 #2
Thank you for your reply. This is a very helpful suggestion and I'll
remember it when I need to use it. For now, I have decided not to use a 2nd
AppDomain.

"Sebastien Lambla" <se**************@6sens.com> wrote in message
news:u$**************@TK2MSFTNGP11.phx.gbl...
Hum, complex topic. What you should do IMO, if the objects you need are
created and consumed in your second AppDomain, is to create a proxy object
that you create from your first AppDomain in your second AppDomain using
CreateInstanceAndUnwrap. If this object inherit from MBR, you can then use
it to call methods that will in fact execute in the second application
domain, and you can, in these methods create your objects or get back the
objects from the out and ref parameters of your C dll. It's then just a
matter of getting the value you want back, and put them in a MBV back to
your first AppDomain to prevent any more marshalling.

This is the only way I could figure to get good encapsulation and prevent a few nifty remoting tricks such as viral dll loading across appdomains :)

--
Sebastien Lambla
http://thetechnologist.is-a-geek.com/blog/
"Mountain Bikn' Guy" <vc@attbi.com> a écrit dans le message de news:
cBRpb.77282$275.206628@attbi_s53...
It is known that one cannot pass arguments as ref or out in a
marshal-by-reference class. My problem is that I have a C DLL (and C#
wrapper) that I need to isolate in an AppDomain and then I need to

interact
with many objects in that DLL and wrapper by reference. (So the classes
inherit from MBRO.) While my app is running, I need to obtain info from
objects in the 2nd app domain frequently/speedily and I need update the

GUI;
and I need to pass user actions back to the DLL. I also need to handle
events across the AppDomain boundary. All this sounds fairly standard, I
guess (I'm new to remoting.)

However, the C# wrapper has a lot of methods that use 'out' parameters,

and
I can't change this (might as well rewrite the whole app from scratch).

So,
my question is, How can I isolate this set of objects in an AppDomain
without throwing all that code away? The methods with ref and out

parameters
could be wholly 'bounded' or contained within the new AppDomain. In other words, these methods are not needed in regard to communicating across the AppDomain boundary, but are only needed for objects within the new

AppDomain
to interact with each other. Any suggestions on how to do this?

On a different but related point, I read in a post from 2001 the

following:
" Fields of App-Domain-bound objects must be accessed through accessors.
so for any objects derived from MarshalByRefObject (as is your TreeNode) you must provide put/get methods (for your color member)."

If I understand that correctly, it means that implementing Properties in
place of certain methods the C# wrapper currently uses for returning

values
would help. But that doesn't solve my main ref/out param issue, but it is interesting. Anyone care to point me to more info on either/both of these topics?

Dave


Nov 15 '05 #3

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

Similar topics

8
by: Vijay | last post by:
Hi all, Im using gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-20) on 64bit linux server im trying to compile following code --------------------sam.cpp--------------------- #include...
1
by: wbaccay | last post by:
I have a byte of binary data received from a NetworkStream (C# code) that I need to pass to the IWMWriter object in a DLL written in Managed extensions for C++ (since the Windows Media SDK is not...
0
by: Kirk Marple | last post by:
i have a large C++ data structure that i'm trying to interop with... the structure is 77400 bytes long. i have the structure defined in C#, so i was trying to just use "ref <structure>" as the...
12
by: glutz7878 | last post by:
I have no trouble passing __delegate ptrs to native C functions in DLLs, however when attempting to pass the __delegate ptr to a native C++ function in a DLL I get the following runtime exception:...
2
by: Joseph Geretz | last post by:
I'm developing a Web Service using DIME to download and upload files from and to an IIS server. In order to increase the download filesize to unlimited, I have the following block in my App.config...
6
by: vladislavf | last post by:
Hi All, I need to pass array of strings from C++/CLI to unmanaged C++ function. (The unmanaged API signatire is : int Combine(int NumOfInputFiles, wchar_t **names) and I want to call it from...
0
by: shengmin.ruan | last post by:
i got a struct like: --------------------- public ref struct OutPacket{ int m_replyIndex; List<MainInfo^>^ m_mainInfos; }; --------------------- when i pass it to another process, i have...
0
by: Madhu_TN | last post by:
Hi All, I am new to this board. I am trying to create a Crystal Report viewer into a VS C++ Dot NET 2003 app ( This uses both managed and unmanaged code). I get the following compilation error:...
11
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Hi, I'm using VS 2005, ,.net 2 for C# windows application. I'm using Process to run a C application and redirecting its standard output so I can read it with StreamReader.ReadToEnd. It's only...
3
by: michelqa | last post by:
Hi, I already post a similar question last week without success. Ok I want to get the current text selection in a RICHEDIT control.. This can be easily done in C++ with EM_EXGETSEL message. I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.