You are here:

C++/Loading dll with classes in DEV-C++

Advertisement


Question
Hi Ralph, thanks in advance for your time.
I want to compile an algorithm in C++ provided by Microsoft that uses a windows dll (system.dll). The thing is, I need to compile in DEV-C++. Is there a way to load this system.dll in the DEV-C++ and use its classes since Microsoft doesn't provide the header?

Just part of the code is:
_____________________________
using <System.dll>

using namespace System;
using namespace System::IO;
using namespace System::IO::Compression;

// ... much more lines here

int main()
{
  array<String^>^args = Environment::GetCommandLineArgs();
  String^ usageText = "Usage: MYGZIP <inputfilename>";
  
  //If no file name is specified, write usage text.
  if ( args->Length == 1 )
  {
     Console::WriteLine( usageText );
  }
  else
  {
     if ( File::Exists( args[ 1 ] ) )
         GZipCompressDecompress( args[ 1 ] );
  }
}
___________________________________

Evidently, when I compile I get error because, I think, "using <System.dll>" is only supported by Microsoft Visual C++.

I also tried to load the dll through LoadLibrary and GetProcAddress functions but I was not sure how to do that and it failed, if you can give me some hint, I'd appreciate it.

Thanks

Answer
In short no you cannot with DevC++ / MinGW C++.

I strongly suggest you learn what is and is not (ISO) standard C++.

Things like:

   #using <System.dll>     // I presume there is in fact a # prefixing the using on this line...

   using namespace System;

   using namespace System::IO;

   using namespace System::IO::Compression;

   array<String^>^args = Environment::GetCommandLineArgs();

   String^ usageText = "Usage: MYGZIP <inputfilename>";

   Console::WriteLine( usageText );

indicate to me that this is a managed C++/CLI program.

That is it is intended for use with the .NET managed runtime environment. As far as I know the Microsoft Visual C++ 2005 and 2008 compilers are the only ones that support this particular super-set of ISO standard C++ - which, by the way, was invented by Microsoft to replace its initial (and ugly as sin) managed C++ extensions. Microsoft submitted to, and had accepted by, the ECMA standards body C++/CLI as an ECMA standard. It was rejected by ISO as far as I know (and last I heard). For more on C++/CLI you might like to start with the Wikipedia article at http://en.wikipedia.org/wiki/C++/CLI (which I was pleased to see concurred with my points made here).

You might like to note the patent application link in the External links section. If granted this may make it difficult for other compilers to implement C++/CLI without licensing from Microsoft (I am no lawyer though so a patent lawyer would be able to give better advice as to the scope of this patent) - which would be especially true for those that are open source such as the GNU compiler collection on which MinGW C++ is based which is what is used by DevC++.

As to loading System.dll - this is _not_ a normal native machine code DLL,  but rather one of the core managed code assemblies of the .NET runtime - on my system (Vista 64 bit) it is located in the Windows\assembly directory on the system partition and appears to be compiled to MSIL (MicroSoft Intermediate Language) used by the .NET JIT (Just In Time) compiler to create native code to execute on the fly.

Please refer to the Microsoft documentation for more on .NET, CLI, assemblies, managed code, MSIL etc.  

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Ralph McArdell

Expertise

I am a software developer with more than 15 years C++ experience and over 25 years experience developing a wide variety of applications for Windows NT/2000/XP, UNIX, Linux and other platforms. I can help with basic to advanced C++, C (although I do not write just-C much if at all these days so maybe ask in the C section about purely C matters), software development and many platform specific and system development problems.

Experience

My career started in the mid 1980s working as a batch process operator for the now defunct Inner London Education Authority, working on Prime mini computers. I then moved into the role of Programmer / Analyst, also on the Primes, then into technical support and finally into the micro computing section, using a variety of 16 and 8 bit machines. Following the demise of the ILEA I worked for a small company, now gone, called Hodos. I worked on a part task train simulator using C and the Intel DVI (Digital Video Interactive) - the hardware based predecessor to Indeo. Other projects included a CGI based train simulator (different goals to the first), and various other projects in C and Visual Basic (er, version 1 that is). When Hodos went into receivership I went freelance and finally managed to start working in C++. I initially had contracts working on train simulators (surprise) and multimedia - I worked on many of the Dorling Kindersley CD-ROM titles and wrote the screensaver games for the Wallace and Gromit Cracking Animator CD. My more recent contracts have been more traditionally IT based, working predominately in C++ on MS Windows NT, 2000. XP, Linux and UN*X. These projects have had wide ranging additional skill sets including system analysis and design, databases and SQL in various guises, C#, client server and remoting, cross porting applications between platforms and various client development processes. I have an interest in the development of the C++ core language and libraries and try to keep up with at least some of the papers on the ISO C++ Standard Committee site at http://www.open-std.org/jtc1/sc22/wg21/.

Education/Credentials

©2016 About.com. All rights reserved.