Click here to Skip to main content
15,890,336 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi there,

I have a question about Interop between C# and C/C++. That's the situation :
- I need to develop a C# dll (MS VS2010)
- A c++ software (C++ Builder IDE) must call this dll in order to do some stuff

This is the code of the calling method (C++) :
C++
// Loading DLL
if (enCr == OK)
{
	asDllName =  asTagValue;// + ".dll";
	sprintf(aucNameDLL, "%s\\%s\\%s.dll", ExtractFileDir(argv[0]).c_str(), asDllName.c_str(), asDllName.c_str());
	if (!(hinstDLL=LoadLibrary(aucNameDLL)))
	{
		enCr = ER_LOAD_DLL;
	}
}

// Launch method
if (enCr == OK)
{
	if ((ImpDllRequest = (DLL_FUNC_REQQUEST)GetProcAddress(hinstDLL, "enXmlRequest"))==NULL)
	{
	enCr = ER_LOAD_FUNCTION;
	}
}


I found some informations about this kind of problem here :
http://www.codeproject.com/KB/cs/ManagedCOM.asp[^]

But I have to put in the C++ software static informations.

Does exists a way to call C# dll in a dynamic way, like my example over.

Not sure my explanations are understable but English is not my foreign language, so just ask questions, I will try to answer.

BaptX
Posted

If you want take C# dll in to native VC++ (VC 6.0 ) runtime then you may
register C# dll as COM class using regasm.exe and call functions ...

and If you are building your projects in vc++ ( VC++ studio 2008 ) with /clr option then you can just add reference of C# dll in C++ software project ....

is this clear or you need something more ...??
 
Share this answer
 
.NET dlls can be loaded dynamically using LoadAssembley.

You can't call a .net dll directly from C++ unless it is a mixed managed and unmanged dll using /CLR.

What I would do in you situation is to create a mixed C++/.NET dll to wrap your c#.Net DLL then call the C++/.NET dll directlt from the C++ dll and call the C#.NET DLL from the C++/.NET DLL as follows:

C++ DLL ---calls---> C++/NET (CLR) DLL---calls----> C#.NET Assembley
 
Share this answer
 
If I understand properly, you said I need to create a DLL which will do interface between my C++ Software and the C# DLL ?

Software --> Mixed DLL --> C# DLL

Is that right ?

I will search on google some informations about mixed DLL.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900