Click here to Skip to main content
15,884,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I created a clr empty project and I added this code :

C++
using namespace System;
using namespace System::IO;



int main()
{
	String^ fileName = "textfile.txt";

	StreamWriter^ sw = gcnew StreamWriter(fileName);
	sw->WriteLine("A text file is born!");
	sw->Write("You can use WriteLine");
	sw->WriteLine("...or just Write");
	sw->WriteLine("and do {0} output too.", "formatted");
	sw->WriteLine("You can also send non-text objects:");
	sw->WriteLine(DateTime::Now);
	sw->Close();
	Console::WriteLine("a new file ('{0}') has been written", fileName);

	return 0;
}





now I want to add a library in c#, I added c# library and I add this to reference of c++ project and I addes this library to build dependencies but if I write in my source cpp:
#using "ClassLibrary1.dll"

there is an erroe: file not found.. and I added dll to c++ exe

What I have tried:

I tried what I wrote above..I tried to add a c# library
Posted
Updated 9-Mar-23 2:51am
v4

Check the bin/debug folder and make sure that the DLL file is in there (or add a project reference instead of a file reference).
 
Share this answer
 
Comments
Member 14594285 9-Mar-23 5:32am    
yes there is, there is an other error:
Severity Code Description Project File Line Suppression State
Error Unable to copy file "obj\Debug\ClassLibrary1.dll" to "bin\Debug\ClassLibrary1.dll".
OriginalGriff 9-Mar-23 6:05am    
That's probably why it doesn't work - if it can't copy the DLL to the executable folder, it won't be able to find it.
Try checking that no other processes / apps have the DLL open.
Member 14594285 9-Mar-23 6:11am    
I close all..error:
Severity Code Description Project File Line Suppression State
Error (active) cannot open metadata file "ClassLibrary1.dll" Project711 c:\Dev2015\Prg\Project711\Project711\Source.cpp 5

Severity Code Description Project File Line Suppression State
Error C1107 could not find assembly 'ClassLibrary1.dll': please specify the assembly search path using /AI or by setting the LIBPATH environment variable Project711 C:\Dev2015\Prg\Project711\Project711\Source.cpp 5

I added path of ClassLibrary.dll to command line but it's the same


This seems rather dated, but maybe it works for you:
Calling Managed .NET C# COM Objects from Unmanaged C++ Code[^]

But it should be simpler when using managed C++ (CLR project), see:
Interoperability with Other .NET Languages (C++/CLI) | Microsoft Learn[^]

It seems possible to use C# winforms from C++ too, see:
How to Integrate C# Window in C++ Project[^]

As I only have limited experience (only with calling C++ from C#), I can not be of much help in this matter.
 
Share this answer
 
v3
Comments
Member 14594285 9-Mar-23 8:57am    
with visual studio 2015 doesn't open
RickZeeland 9-Mar-23 9:00am    
Try the second example, its written for VS2015
Member 14594285 9-Mar-23 9:14am    
project works..a question..Can I use a dialog and not a console?
Member 14594285 9-Mar-23 9:42am    
it works..but a question..can I add a dialog?
RickZeeland 9-Mar-23 12:49pm    
See the updated solution above, good luck!

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