![]() You should now be able to compile and run the unmanaged client application,accessing the C# or VB.NET component that you created in the previous example.Running the unmanaged client produces the output shown in Figure 3.įigure 3 The unmanaged C client accessing CLR components created usingC# or VB.NET. On the right side,for the Debug Information Format, select Program Database (/Zi).Ĭlick OK to apply the configuration changes and close the Propertiesdialog. On the left side of the dialog, select C/C , General. For the EnableMinimal Rebuild entry, select No. ![]() For theRuntime Library entry, select Multi-threaded Debug (/MTd). On the left side of the Properties dialog, select C/C , Code Generation.On the right side, for the Basic Runtime Checks entry, select Default. The settings youchange from here on affect only the Debug builds. In the Configuration combo box, select Active(Debug). On the right side, in the Create/Use Precompiled Headers section,select Not Using Precompiled Headers. On the left side of the Properties dialog, select C/C , PrecompiledHeaders. Because thesolution file isn't located in the project directory for either componentin this example, you can't use the $(SolutionDir) label. On your system, replace the relative path specified with the actualpath to the project directories on your system if necessary. If you are using the VB component, enter: copy ".\VBTaxCalc\bin\VBTaxCalc.dll" $(ConfigurationName) On the right side, in the Command Line entry, if you are using the C#component, enter: copy ".\CSTaxCalc\bin\$(ConfigurationName) \CSTaxCalc.dll" $(ConfigurationName) On the left side of the Properties dialog, select Build Events, Pre-BuildEvents. In the Solution Explorer pane, select the UnmgdClient projectnode. On the right side, in the Create/Use Precompiled Headers entry, selectNot Using Precompiled Headers. In the Solution Explorer pane, select the stdafx.cpp file. On theright side, for the Compile As Managed entry, specify Assembly Support (/clr).For the Resolve #using References entry, enter $(outdir).Ĭlick the Apply button to apply the configuration changes without closingthe Properties dialog. On the left side of the Properties dialog, select C/C , General. On the Configuration combo box, select All Configurations. In the Solution Explorer pane, select and right-click the project nodefor the MgdClient.cpp file. Listing 7The GetTaxes Function doubleMgdClient::GetTaxes(double dbPurchaseAmt, wchar_t* strCategory) Specify the firstparameter type as double and the name as dbPurchaseAmt.Specify the second parameter type as wchar_t* and the name as strCategory.Įdit the new function as in Listing 7. Specify the returnvalue for the new function as double, the name as GetTaxes,the access as public, and add two parameters. Name the new class MgdClient.Īdd a new function to the MgdClient class. ![]() To create the interface, followthese steps:Īdd a new generic class to the project, using the same method as in priordays. ClickFinish to create the project.Ĭreating the managed interface for the CLR components is similar to creatingthe managed wrapper for your ATL component. In the Win32 Application Wizard, select Application Settings on the leftside, and then specify Console application for the application type. Ifthe previous example project is still open, be sure that the Close Solutionradio button is selected. Select Visual C Projects on the left side of the New Project dialog,and Win32 Project on the right side. Select New and then Project from the File menu. To create the project, follow these steps: It is with the configuration of theproject where things start to get messy. Creating the codeto enable an unmanaged C application to access components created with C# andVB.NET is simple and fairly straightforward. With the final example, things start to get really sticky. Learn More Buy Building an Unmanaged C Client Sams Teach Yourself Visual C .NET in 21 Days, 2nd Edition
0 Comments
Leave a Reply. |