Exam Prep Questions

Question 1

Your application uses a communications library from a third-party developer, and this library is implemented as a COM component. You are migrating your application to .NET. What should you do to continue to use the classes and methods in the communications library?

  • A. Obtain a primary interop assembly from the developer of the library, and install the PIA in the GAC.

  • B. Use the Type Library Importer to create a signed RCW for the library, and install the RCW in the GAC.

  • C. Use the Type Library Importer to create an unsigned RCW for the library, and install the RCW in the GAC.

  • D. Create wrapper code that uses PInvoke to call functions from the library, and import this wrapper code into your application.

A1:

Answer A is correct. The proper way to proceed is to obtain a PIA from the original author. Answer B is incorrect because you did not write the code for the communications library and therefore cannot sign it. Answer C is incorrect because only signed assemblies can be installed in the GAC. Answer D is incorrect because PInvoke is not used for invoking COM components .

Question 2

You have an existing COM component that contains shared classes, which encapsulate functionality you want to use in your ASP.NET application. How can you use these classes while maintaining the benefits of managed code, such as type safety and automatic garbage collection?

  • A. Use the Type Library Importer with the /strictref option to create an RCW for the COM component.

  • B. Call the methods from the COM component directly via PInvoke.

  • C. Add a direct reference to the COM component.

  • D. Rewrite the COM component as a .NET component.

A2:

Answer D is correct. Only managed code benefits from the features of the CLR, and the only way to turn the component into managed code is to rewrite it in .NET. Answers A and C are incorrect because these techniques just create a wrapper over the existing COM code. The COM code is not converted to the managed code. Answer B is incorrect because PInvoke is not for used for invoking COM components.

Question 3

Your application uses the GetComputerName() API function. This function exists in kernel32.dll in both ANSI and Unicode versions. Your declaration is as follows :

 [DllImport("kernel32.dll")] public static extern int GetComputerName(     StringBuilder buffer, ref uint size); 

Your code is failing with a System.EntryPointNotFoundException exception when you call this function. What should you do to fix this failure?

  • A. Supply the full path for kernel32.dll .

  • B. Add the CharSet.Auto parameter to the declaration.

  • C. Declare the function as GetComputerNameA() instead of GetComputerName() .

  • D. Declare the function as GetComputerNameW() instead of GetComputerName() .

A3:

Answer B is correct. The CharSet.Auto parameter is necessary to tell the CLR to use the ANSI or Unicode version of the function as appropriate to the operating system. Answer A is incorrect because the program automatically searches for the DLL file in the Windows system directory. Answers C and D are incorrect because the GetComputerName function exists as GetComputerNameA (for ANSI characters ) and GetComputerNameW (for Unicode characters) and the system cannot determine which one to invoke.

Question 4

You are responsible for migrating an existing ASP application to ASP.NET. The existing application consists of eight COM server components and a single client user interface component (written as a set of ASP pages) that instantiates and invokes objects from the server components. You want to give the user interface of the application an overhaul and migrate to ASP.NET with low risk and minimal downtime. How should you proceed?

  • A. Completely rewrite the entire application using Visual C# .NET.

  • B. Convert the user interface component from ASP to ASP.NET. Use a COM interop to call the existing COM servers from the .NET user interface code, and then migrate the servers one by one.

  • C. Convert all the server components into Visual C# .NET. Use a COM interop to call the converted server components from the existing ASP pages.

  • D. Cut and paste all the existing code into a Visual C# ASP.NET project.

A4:

Answer B is correct. Converting the user interface component from ASP to ASP.NET and then migrating the servers one by one provides the most effective solution. Answers A and D are incorrect because moving all the code takes longer than moving part of the code, and doing so introduces additional risk. Answer C is incorrect because, if you want to rewrite the user interface, you should move that component to .NET before moving the server components.

Question 5

You wrote a COM component to supply random numbers in a specific distribution to a simple statistical client program. Now you're moving that client program to .NET. The COM component is used nowhere else, and you have not shipped copies to anyone else. You want to call the objects in the COM server from your new .NET client. How should you proceed?

  • A. Set a direct reference from your .NET client to the COM server.

  • B. Use the Type Library Importer to create an unsigned RCW for the COM component.

  • C. Use the Type Library Importer to create a signed RCW for the COM component.

  • D. Use PInvoke to instantiate classes from the COM component.

A5:

Answer A is correct. For components used in a single project, and that you've written, the simple method of creating the RCW is best. Answer B is incorrect because only signed assemblies can be installed in the GAC. Answer C is incorrect because you are not distributing the code to other developers and therefore signing is not required. Answer D is incorrect because PInvoke is not used for invoking COM components.

Question 6

You're moving a legacy ASP application to ASP.NET. Some of the pages use ADO to load data. You use the Server.CreateObject() method to create the ADO connection. Other parts of the application work fine, but those pages that call Server.CreateObject() will not load. What must you do to use the ADO objects in your ASP.NET application?

  • A. Use a Page directive to set the ASP compatibility mode.

  • B. Build an RCW for the ADO objects.

  • C. Convert the ADO objects to ADO.NET.

  • D. Use a Page directive to set the page language to VBScript.

A6:

Answer A is correct. The ADO library uses STA as its threading model, and the .NET Framework allows only STA components on a page that's set to ASP compatibility mode. Answer B is incorrect because you can use the Server.CreateObject() method to create late-bound calls to ADO without the need to build an RCW. Answer C is incorrect because this requires you to write more code. Answer D is incorrect because VBScript is not supported in .NET Framework programs.

Question 7

Your project contains the following API declaration:

 [DllImport("kernel32.dll", CharSet=CharSet.Auto)] public static extern int GetComputerName(String buffer, ref unit size); 

The project also contains the following code to use this API to display the computer name :

 public static void ShowName() {     String buf = "";     UInt32 intLen=128;     Int32 intRet;     // Call the Win API method     intRet = GetComputerName(buf, ref intLen);     Console.WriteLine("This computer is named " + buf.ToString()); } 

Users report that no computer name is displayed. What should you do?

  • A. Use ref with the variable buf in the call to the GetComputerName() function.

  • B. Tell the users that their computers have no names set in their network properties.

  • C. Replace the use of String with StringBuilder in the code.

  • D. Use out with the variable buf in the call to the GetComputerName() function.

A7:

Answer C is correct. In the PInvoke calls, you should use StringBuilder instead of the String data type to hold the return value. Answers A and D are incorrect because using ref or out with the variable buf will not match the methods prototype in the declaration. Answer B is incorrect because all computers do have some name associated with them.

Question 8

Your application will use functions from a COM+ component that uses COM+ for publish-and-subscribe events and object pooling. Which of these methods can you use to access the classes in the COM+ component? (Select two.)

  • A. Use PInvoke to declare the functions in the COM+ component.

  • B. Add the COM+ component directly to the Visual C# .NET Toolbox.

  • C. Set a direct reference to the COM+ component.

  • D. Use the Type Library Importer to create an RCW for the COM+ component.

A8:

Answers C and D are correct. You can use COM+ components through the same techniques you use with COM components. Answer A is incorrect because PInvoke cannot be used to invoke COM+ components. Answer B is incorrect because COM+ components are not controls and cannot be added to the Visual C# .NET Toolbox.



MCAD Developing and Implementing Web Applications with Visual C#. NET and Visual Studio. NET (Exam [... ]am 2)
MCAD Developing and Implementing Web Applications with Visual C#. NET and Visual Studio. NET (Exam [... ]am 2)
ISBN: 789729016
EAN: N/A
Year: 2005
Pages: 191

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net