473,779 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

.Net COM Server Interop

1 New Member
Hi everybody,

I'm working on exposing a .Net (C#) COM Server. Manage Code is exposting an interface with two methods. These methods take an IN/OUT Struct as parameter. Requirement is that the unmanaged client (C++) will initialize the struct fields with some values and these struct values can be modified or reallocated by Managed COM Server.
Struct look something like this on the managed side:
[ComVisible(true )]
[Guid("<guid>")]
[StructLayout(La youtKind.Sequen tial, CharSet = CharSet.Unicode )]
public struct MyStruct
{
string s1; //tlb maps to LPWSTR s1]
string[] arrayS2 //tlb maps to SAFEARRAY* arrayS2
byte[] arrayByte //tlb maps to SAFEARRAY* arrayByte
}
Interface is defined as:
[ComVisible(true )]
[Guid("<someguid >")]
public interface MyInterface
{
int MyMethod1([In, Out] ref MyStruct myStruct);
....
}

Unamanged C++ client will be allocating the MyStruct on heap, give some heap allocation using CoTaskMemAlloc and values to s1, arrayS2 and arrayByte. Manged Server will read these values and can potentially reallocated all the fields of the myStruct.

My understanding is that the Interop Marshall (in the above scenario) will fcopy the struct and all its fields to new Struct and free the fields (which are allocated by CoMemTaskAlloc) and pass it to ManagedCode -- ManagedCode then play with the struct and its field as needed and reallocated if required. Now while returning the Interop marshall will (using CoMemTaskAlloc) copy all the fields of the Struct back to myStruct and pass to the unmanaged client. Its unmanaged client's responsibility to free the fields of myStruct once it is done with the structure.

1> Is my understanding correct?
2> Is there a better way to achieve the above [again re-emphasising the requirement: umanaged client need to pass a struct to managed COM server with fields initialized AND managed server need to return the Struct with its fields reallocated/reinitialized.

Thanks for any help/suggestion,
user2008.
Apr 3 '08 #1
0 1161

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2353
by: David Dolheguy | last post by:
I am in desperate need to get help in answering some questions in regards to building a DCOM Server using C#. I need to create a DCOM server using C#.NET, I realise that you first need to create the managed code, attach interfaces and use the CCW command line tool to add a COM wrapper to the assembly. The server will be communicating with a DCOM client which I didn't write, but I have all the documentation on what interfaces and...
3
2237
by: Kevin | last post by:
Is it possible to develop an Active Document Full Server or a Container application using C#? Thanks, Kevin.
15
2471
by: randyr | last post by:
I am developing an asp.net app based on a previous asp application. in the asp applications global.asa file I had several <object id="id" runat="server" scope="scope" class="comclass"> tags for objects that the app used to speed up some global level data access and functionality. I have recoded the class libraries in .net and would like to acomplish the same functionality in asp.net.
5
2641
by: Dave A | last post by:
I am writing an ASP.NET tool that will allow the client to create their own online froms. ie the client can add tect boxes, text, drop downs,etc with absolutely no technical skill what so ever. The form can then be deployed to their intranet. The form designer is somewhat WYSIWYG but it contains a heap of 'edit', 'delete' and reordering buttons that are not seen when the form is acutally being used. I would love to have a preview...
3
3622
by: Hari Menon | last post by:
I am writing a C# client (using .NET 1.1) to a web service built on Apache Axis. The server returns an array using multirefs but the C# client does not seem to be able to recognize it. I read in one of the articles that I should turn multirefs OFF for interop with .NET and that there was some microsoft technote stating this. Does the .NET framework 1.1 support multirefs sent by a service? If not,
0
998
by: Kurtz | last post by:
Hi, I developed a web application that run complete (all the functions) in a server with Visual Studio .NET 2003, but not run complete in a web server with .NET framework (both versions) and without Visual Studio. The web application call a "first" dll build that call a "second" interop dll and only execute the first steps. Here is the code of the web application in C#:
2
7304
by: JC | last post by:
Anybody knows what problem has this code? I think, in the Garbage Collector? You know the Solution? The program in the test's case, whit 350 contacts, run OK before number 86. The error is a "Array index out of bounds". Microsoft.Office.Interop.Outlook._Application olApp = new Microsoft.Office.Interop.Outlook.ApplicationClass(); Microsoft.Office.Interop.Outlook._NameSpace olNs = olApp.GetNamespace("MAPI");
3
2678
by: =?Utf-8?B?c3BkMzAwMQ==?= | last post by:
I have a C++/CLI app that uses a logging control in an ATL COM Server. C++ Interop seems to work just fine to pass data from the C++/CLI app to the ATL Control but I can't seem to figure out how to get a string value back from the ATL Control. When debugging the code seen below, I see that the VARIANT pointed to by 'data' is updated but the String 'str' passed from the C++/CLI app doesn't change. So the String 'str' seems to be passed by...
2
4435
by: saketmayur | last post by:
Hi , I have write the following code to open word document on server using Microsoft.Office.Interop.Word; string DocPath = System.Configuration.ConfigurationManager.AppSettings; ApplicationClass wordApp = new ApplicationClass(); string filePath = ""; filePath = DocPath + Session + "/" + DocFile.Value.ToString();
0
9636
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10306
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10074
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8961
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6724
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5503
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.