Click here to Skip to main content
15,881,248 members
Articles / Programming Languages / C#

Using P/Invoke in a managed C++ application

Rate me:
Please Sign up or sign in to vote.
3.50/5 (2 votes)
15 Oct 20011 min read 103K   1.6K   18  
This article demonstrates interoperability between .NET managed code and old unmanaged code. It uses the P/Invoke mechanism to call unmanaged DLL entry points.
<?xml version="1.0"?>
<VisualStudioProject
	ProjectType="Visual C++"
	Version="7.00"
	Name="PInvokeDemo"
	Keyword="managed c">
	<Build>
		<Settings>
			<Platform
				Name="Win32"/>
			<Configuration
				Name="Debug|Win32"
				IntermediateDirectory="Debug"
				OutputDirectory="Debug"
				ConfigurationType="1"
				CharacterSet="2"
				ManagedExtensions="TRUE">
				<Tool
					Name="VCBscMakeTool"/>
				<Tool
					Name="VCCLCompilerTool"
					Optimization="0"
					Defines="WIN32;_DEBUG"
					MinimalRebuild="TRUE"
					FullRuntimeChecks="FALSE"
					WarnLevel="3"
					SuppressStartupMessage="TRUE"
					DebugInformation="3"/>
				<Tool
					Name="VCCustomBuildTool"/>
				<Tool
					Name="VCLinkerTool"
					IgnoreExportLibrary="TRUE"
					AdditionalInputs="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib"
					OutputFile="$(OutDir)/PInvokeDemo.exe"
					LinkIncremental="2"
					SuppressStartupMessage="TRUE"
					GenerateDebug="TRUE"/>
				<Tool
					Name="VCMIDLTool"/>
				<Tool
					Name="VCPostBuildEventTool"/>
				<Tool
					Name="VCPreBuildEventTool"/>
				<Tool
					Name="VCPreLinkEventTool"/>
				<Tool
					Name="VCResourceCompilerTool"/>
				<Tool
					Name="VCSDLTool"/>
			</Configuration>
			<Configuration
				Name="Release|Win32"
				IntermediateDirectory="Release"
				OutputDirectory="Release"
				ConfigurationType="1"
				CharacterSet="2"
				ManagedExtensions="TRUE">
				<Tool
					Name="VCBscMakeTool"/>
				<Tool
					Name="VCCLCompilerTool"
					Optimization="2"
					InlineFunctionExpansion="1"
					Defines="WIN32;NDEBUG"
					MinimalRebuild="FALSE"
					WarnLevel="3"
					SuppressStartupMessage="TRUE"/>
				<Tool
					Name="VCCustomBuildTool"/>
				<Tool
					Name="VCLinkerTool"
					IgnoreExportLibrary="TRUE"
					AdditionalInputs="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib"
					OutputFile="$(OutDir)/PInvokeDemo.exe"
					LinkIncremental="1"
					SuppressStartupMessage="TRUE"
					GenerateDebug="FALSE"/>
				<Tool
					Name="VCMIDLTool"/>
				<Tool
					Name="VCPostBuildEventTool"/>
				<Tool
					Name="VCPreBuildEventTool"/>
				<Tool
					Name="VCPreLinkEventTool"/>
				<Tool
					Name="VCResourceCompilerTool"/>
				<Tool
					Name="VCSDLTool"/>
			</Configuration>
		</Settings>
	</Build>
	<Files>
		<Filter
			Name="Source Files"
			Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat;asm">
			<File
				RelativePath="AssemblyInfo.cpp">
			</File>
			<File
				RelativePath="PInvokeDemo.cpp">
			</File>
		</Filter>
		<Filter
			Name="Header Files"
			Filter="h;hpp;hxx;hm;inl;inc">
		</Filter>
		<Filter
			Name="Resource Files"
			Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
		</Filter>
		<File
			RelativePath="ReadMe.txt">
		</File>
	</Files>
	<Globals>
	</Globals>
</VisualStudioProject>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions