473,542 Members | 7,688 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4702
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
18019
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 <string> #include <iostream> #include <stdarg.h>
1
2409
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 usable in C#) whose WriteSample function takes a byte* parameter Do I need to marshal data? I thought I did, so I ran into alot of issues with...
0
2220
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 method parameter. if i use this direct approach, i get the error: Message: Cannot marshal 'parameter #1': Internal limitation: structure is too...
12
1695
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: An unhandled exception of type 'System.EntryPointNotFoundException'. This is confusing b/c if the entry point was not found, I would think I'd...
2
14330
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 and Web.config files: <messaging> <maxRequestLength>-1</maxRequestLength> </messaging> The largest file I've downloaded is 70 meg and that's...
6
10290
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 C++/CLI code by using C++ Interop ) But unfortunately I have only one day experience in C++/CLI so all my attempts are failing.
0
1635
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 to transfer it to intptr :
0
3672
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: C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\ cstringt.h(875): error C2664: 'PtrToStringChars' : cannot convert parameter 1...
11
9211
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 reading the 1st 5 lines or so when there is about 30 lines of data. I also tried using the Process.BeginOutputReadlin and a DataReceivedEvntHandler to...
3
6137
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 really need to do the same thing in C#. How can I put the structure in memory to be able to call SendMessage and get the expected results in the...
0
7384
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7322
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7718
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7316
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5239
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4878
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3377
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1790
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
941
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.