473,413 Members | 1,705 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,413 software developers and data experts.

Consuming C# dll from unmanaged C++ exe; StringCollection

I have a case where a C# dll is being consumed by an unmanaged C++
executable. One of the dll methods returns a StringCollection object. What
are the requirements for the C++ executable in terms of .h, .tlb files to be
included/imported, and the syntax for consuming the StringCollection object?

TIA.
Oct 17 '06 #1
2 2153

"eSapient" <eS******@discussions.microsoft.comwrote in message
news:7F**********************************@microsof t.com...
>I have a case where a C# dll is being consumed by an unmanaged C++
executable. One of the dll methods returns a StringCollection object. What
are the requirements for the C++ executable in terms of .h, .tlb files to
be
included/imported, and the syntax for consuming the StringCollection
object?
You can use .NET via COM, see "Runtime Callable Wrapper". However that
might not be the easiest way to go.

Is the .dll a hard dependency (exe can't work without it) or a soft
dependency (lose some features but press forward)?

If it is a hard dependency, then your exe is actually dependent on the .NET
framework (exe needs dll needs framework). In that case, see if your exe
works correctly when built with /clr.
>
TIA.

Oct 20 '06 #2
I created a .NET class library with the following C# code:

using System;
using System.Runtime.InteropServices;
using System.Collections.Specialized;

namespace ClassLibrary3
{
[GuidAttribute("6F66DEAB-1BCF-4ce4-AB06-D298BA2B56CA")]
public class MyClass : IMyClass
{
public MyClass()
{}

void IMyClass.MyMethod(out StringCollection strings)
{
strings = new StringCollection();
strings.Add("First string");
strings.Add("Second string");
}
}

[GuidAttribute("F26D63B9-C3A8-4f1a-9B17-1C441DE58EAF")]
public interface IMyClass
{
void MyMethod(out StringCollection strings);
}
}

I registered this project for COM Interop.

I then created a console application in VC++, where I added a reference to
the class library project (both projects are in the same solution). I am not
very familiar with COM programming using C++. My intention is to consume the
class library above in unmanaged C++. I added the following code in the
console application, but it is incomplete since I don't know how to go about
it.

#include "stdafx.h"

#import "mscorlib.tlb"
//#import "..\ClassLibrary3\bin\Debug\ClassLibrary3.tlb"

#using <mscorlib.dll>

using namespace System;
using namespace System::Collections::Specialized;
//using namespace ClassLibrary3;

int _tmain()
{
::CoInitialize(0);
ClassLibrary3::IMyClassPtr pIMyClass(__uuidof(ClassLibrary3::MyClass));
// pIMyClass.MyMethod();

return 0;
}

Can somebody help me and show me how to consume the .NET class?

Thanks in advance.
Oct 29 '06 #3

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

Similar topics

2
by: Dan | last post by:
Hi, Is it possible to iterate through a StringCollection ? I have the following code but "row" always seems to contain the values of rowValues2 Thanks for any input, Danny
1
by: Sin | last post by:
Hello everyone, I'm currently trying to migrate a MSVC6 project to .NET... The straight conversion (ie : unmanaged) was extremely straightforward. Now I'm trying to compile and hopefully run the...
8
by: Naz | last post by:
Hi, I am new in C# and converting a program from delphi to C#. I have to store a list of strings in memory and also need to save the strings to disk at the end. I use StringCollection and my...
0
by: Eric Twietmeyer | last post by:
Hello, Am I mistaken in thinking that if I have a mc++ dll that I should be able to link against it (so long as it has exported symbols via declspec(dllexport)) in an unmanaged application? I...
15
by: Chetan Raj | last post by:
Hi All, We have a web-application in asp.net that interacts with legacy code written in COM. The memory usage in aspnet_wp.exe increases every sec and never reduces. Using the .NET performance...
2
by: interX | last post by:
Hi, I have a little problem with managed/unmanaged in Visual Studio 2005 (Compiler setting /clr). I need to overhand several function pointers from managed to unmanaged. These function pointers...
1
by: Arne Adams | last post by:
Hi, I try to use a C# Dialog in a legacy MFC application. The problem seems to boil down to the following: from an unmanaged console application I can call any function of the managed bridge - if...
7
by: Tremendo | last post by:
Hi, I need to consume an unmanaged DLL from managed C#. The DLL is "ae766.dll". I have problems with one function in it. Who developed the DLL, provided the following information, regarding that...
4
by: Mau | last post by:
Hi, I have a managed dll which I am accessing from an unmanaged exe using Com Interop. I installed everything on computer 1 and run the unmanaged exe and from exe called my managed dll and...
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?
0
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,...
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...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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...

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.