Efficient use of unmanaged parallel caching in C++/CLI

Source: Internet
Author: User
Tags command line win32 error visual studio

How can Visual Studio Setup put Visual Studio's shared library in a place called side-by-side cache, and how do you use it effectively?

At the beginning of the article, let's look at an example. On the command line, create a C + + source file and enter the code in Example 1. (Although the C++/CLI syntax is used here, it doesn't matter if you're using C++/CLI, managed C + +, or local C + +, and it doesn't affect the topic you want to explain.) )

Case 1:lib.cpp

using namespace System;
public ref class Test
{
  public:
   void CallMe()
   { 
    Console::WriteLine("called me");
   }
};

Compile it into a managed library assembly:

cl /clr /LD lib.cpp

Notice here that we are using mixed mode (/clr) to compile this code, and of course, if properly modified, it can be compiled with legacy managed C + + syntax (/clr:oldsyntax).

Next, create a C # program that calls this library (example 2), and of course you can use Visual Basic.NET, but C # is a little better. And then compile with the library:

Example 2:

using System;
class App
{
  static void Main()
  {
   Test test = new Test();
   test.CallMe();
  }
}
csc app.cs /r:lib.dll

When you run this program, an exception is thrown:

Unhandled Exception:
System.IO.FileNotFoundException:
The specified module could not be found.
(Exception from HRESULT: 0x8007007E)
at App.Main()

How could that be? Open the directory where the program resides, and the library is there. The high word for HRESULT is 0x8007, which represents Facility_win32, that is, this is a Win32 error; the low word is in decimal notation 126, and its representative Error_mod_not_found is listed in the Winerror.h. If LoadLibrary cannot find a module, it returns this error result, so it is now very clear that this error indicates that an unmanaged DLL could not be traced.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.