Exam Prep Questions

Team-Fly    

Developing XML Web Services and Server Components with Visual C#™ .NET and the .NET Framework, Exam Cram™ 2 (Exam 70-320)
By Amit Kalani, Priti Kalani

Table of Contents
Chapter 9.  Calling Unmanaged Code


Question 1

Your colleague needs to make a call to a COM component named State.dll from a serviced component registered as a COM+ server application. You suggest to her that she use the Type Library Importer tool. What command-line option should you suggest so that the serviced component can access the methods of the COM component?

  • A. Use the /keyfile option to assign a strong name to the COM component.

  • B. Use the /reference option to set the reference to the serviced component.

  • C. Use the /primary option to produce a primary interop assembly.

  • D. Use the /unsafe option to disable the .NET Framework security checks.

A1:

Answer A is correct. The RCWs referenced by serviced components must be strongly named. Therefore, with the given choices, you need to select the /keyfile command-line option of the tlbimp.exe tool. The /keyfile option is passed a filename that contains the public/private key pair to strongly sign an assembly. Answer B is incorrect because the /reference option specifies a file to be used to resolve references from the file being imported. Answer C is incorrect because the /primary option produces a primary interop assembly. Answer D is incorrect because the /unsafe option creates interfaces without the .NET Framework security checks.

Question 2

Your Web service needs to use a library from a third-party developer to encrypt and decrypt messages. This library is implemented as a COM component. What should you do to continue to use the classes and methods in the communications library?

  • A. Obtain a PIA from the developer of the library. Install the PIA in the GAC.

  • B. Create wrapper code that uses platform invoke to call methods from the library. Import this wrapper code into your application.

  • C. Use the Type Library Importer tool to create a signed RCW for the library. Install the RCW in the GAC.

  • D. Use the Type Library Importer tool to create an unsigned RCW for the library. Install the RCW in the GAC.

A2:

Answer A is correct. Because you did not write the code for the library, you are not allowed to sign code written by someone else. Therefore, the best way to proceed is to obtain a PIA from the original author. Answer B is incorrect because platform invoke cannot call methods from COM libraries. Answers C and D are incorrect because the code is from a third-party developer, and you should not create RCWs for others' code.

Question 3

You want to use an unmanaged DLL named Customer.dll in your Visual C# .NET application. Customer.dll does not provide any COM interfaces. How can you call the RetrieveBalance() method of this library in your .NET code?

  • A. Use the Type Library Importer tool.

  • B. Use the Windows Forms ActiveX Control Importer tool.

  • C. Use the DllImport attribute to declare the extern method RetrieveBalance() from Customer.dll.

  • D. Add a reference to the Customer.dll library in your Visual Studio .NET project.

A3:

Answer C is correct. Only the PInvoke feature of .NET enables you to call methods from unmanaged DLLs that do not provide any COM interfaces. You need to use the DllImport attribute to tell the .NET Framework where to find the implementation of a method call. Answers A and D are incorrect because they work only with COM components. Answer B is incorrect because the Windows Forms ActiveX Control Importer tool works with ActiveX controls rather than unmanaged libraries.

Question 4

Your application will use methods from a COM component that uses COM+ services such as object pooling and just-in-time activation. Which of these methods can you use to access the classes in the COM component? (Select the two best answers.)

  • A. Use platform invoke to declare the methods within the COM component.

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

  • C. Set a direct reference to the COM component in your Visual Studio .NET project.

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

A4:

Answers C and D are correct. You can use COM components that use COM+ services by using the same techniques that you use with COM components. Therefore, you can either set a direct reference to the COM component or use the Type Library Importer tool to create an RCW for the COM component. Answer A is incorrect because platform invoke cannot be used to call methods from COM components. Answer B is incorrect because COM components need not be added to the toolbox.

Question 5

You have written several applications for your own use, all of which share classes from a COM component that you also wrote. You are moving the applications to .NET, but you intend to leave the COM component untouched. How should you proceed?

  • A. Set a direct reference from each application to the existing COM component.

  • B. Use the Type Library Importer tool to create an unsigned RCW for the COM component. Place a copy of this RCW in each application's directory.

  • C. Use platform invoke to call methods from the existing COM component in each application.

  • D. Use the Type Library Importer tool to create a signed RCW for the COM component. Place this RCW in the GAC.

A5:

Answer D is correct. A COM component that is shared by multiple applications should be placed in the GAC. The Type Library Importer tool enables you to create a signed RCW so that it can be placed in the GAC. Answers A and B are incorrect because components used by more than one application should be shared and stored in a common place such as the GAC rather than with individual applications. Answer C is incorrect because platform invoke cannot call methods from COM components.

Question 6

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().

A6:

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 automatically determine which one to invoke without the CharSet.Auto parameter.

Question 7

You are responsible for migrating an existing COM application to Visual C# .NET. The existing application consists of eight COM server components and a single client user interface component that instantiates and invokes objects from the server components. You want to give the application's user interface an overhaul and migrate to Visual C# .NET with low risk and minimal downtime. How should you proceed?

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

  • B. Bring only the user interface code into Visual C# .NET. Use COM interoperability to call the existing COM servers from the .NET user interface code. Migrate the servers one by one.

  • C. Convert all the server components into Visual C# .NET. Use COM interoperability to call the migrated servers from the existing user interface code.

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

A7:

Answer B is correct. Converting the user interface code 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 8

Your Visual C# .NET application uses functions from a Visual Basic 6.0 COM library implemented as a DLL via an RCW. You built the RCW by directly referencing the COM DLL. Users are complaining of poor performance. Which of these changes is most likely to improve the performance of your application?

  • A. Recompile the Visual Basic 6.0 library as an EXE file.

  • B. Switch your .NET application from Visual C# .NET to Visual Basic .NET.

  • C. Use the Type Library Importer to create a new RCW.

  • D. Rewrite the Visual Basic 6.0 library as a native .NET library.

A8:

Answer D is correct. Rewriting the library into .NET is likely to speed it up because it eliminates the extra calls to the proxy layer. Answers A and B are incorrect because changing from a DLL to an EXE or from C# to Visual Basic .NET will have no significant effect on performance. Answer C is incorrect because RCWs are the same, no matter how they're created.

Question 9

You are using three classes from a COM component in your Visual C# .NET application. You'd like to give the RCW for the COM component the same version number as the rest of your components when you ship the application. What should you do?

  • A. Use Platform Invoke to call methods from the COM component, thus eliminating the RCW.

  • B. Directly import the COM component into the References list. Right-click the reference and select Properties to set the version number.

  • C. Recompile the existing COM library with the desired version number before creating the RCW.

  • D. Use the Type Library Importer tool with the /asmversion option to explicitly set the version of the RCW.

A9:

The correct answer is D. Only the Type Library Importer tool can explicitly set the version number for an RCW. Answer A is incorrect because platform invoke cannot call methods from COM components. Answers B and C are incorrect because they don't let you explicitly set the version number for an RCW.

Question 10

Your application uses a COM component stored in a file named ProcessOrders.dll. You deploy the application via xcopy on the test server. Testers report that the orders are not being processed. The test server does have the .NET Framework installed. What could be the problem?

  • A. The COM component needs to be registered on the problem computers.

  • B. ProcessOrders.dll is not stored in the Windows System directory.

  • C. The problem computers are not connected to the Internet.

  • D. Service Pack 1 for the .NET Framework is not installed on the problem computers.

A10:

Answer A is correct. The COM component must be registered in the Windows Registry. Answer B is incorrect because you need to register the component in the Windows Registry instead of just copying it into the Windows System directory. Answers C and D are incorrect because .NET does not require the Internet to run, nor do RCWs depend on Service Pack 1.


    Team-Fly    
    Top


    MCAD Developing XML Web Services and Server Components with Visual C#. NET and the. NET Framework Exam Cram 2 (Exam Cram 70-320)
    Managing Globally with Information Technology
    ISBN: 789728974
    EAN: 2147483647
    Year: 2002
    Pages: 179

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