C++ DLL에서 내 보낸 함수를 사용하도록 요구하는 요구 사항이 있습니다.C++ DLL에서 C# 코드를 사용하려면 어떻게해야합니까?
내 보낸 함수 내에서 일어날 필요가있는 내용이 많이 있지만, 작성하기 위해 작성한 모든 C# 코드를 다시 작성하고 싶지는 않습니다.
저는 C# 코드를 DLL에 붙여 넣기 만하면됩니다.
참고 : 저는 C# DLL을 호출하고 싶지 않습니다. C# 코드를 C++ DLL에 넣고 싶습니다.
// InstallCheckWin32.cpp : Defines the exported functions for the DLL application.
//
#include "stdafx.h"
#include "InstallCheckWin32.h"
#include <tchar.h>
INSTALLCHECKWIN32_API void CallCSharp()
{
// this is where I want to use C# objects
// eg:
DateTime now = DateTime.Now;
}
: 여기
// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the INSTALLCHECKWIN32_EXPORTS
// symbol defined on the command line. This symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// INSTALLCHECKWIN32_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
#ifdef INSTALLCHECKWIN32_EXPORTS
#define INSTALLCHECKWIN32_API __declspec(dllexport)
#else
#define INSTALLCHECKWIN32_API __declspec(dllimport)
#endif
INSTALLCHECKWIN32_API void CallCSharp();
이 .cpp 파일입니다 : 여기
LIBRARY InstallCheckWin32
EXPORTS
IsConnectionPointValid @1
fnTest @2
가 DLL 내 .H 파일입니다 : 여기
는 Exports.def 파일입니다 Common Language Runtime Support (/ clr)에 일반 구성 속성 인 "공용 언어 런타임 지원"을 설정했습니다
C++ 코드에서 C# 코드를 사용하려면 어떻게해야합니까?
감사
기본 C++ \ cli 튜토리얼을 아직 보지 않았습니까? 나는 그들이 심지어'DateTime.Now' 예제를 가질 것이라고 확신합니다. –
이 DLL은 내 보낸 함수가있는 표준 Win32 dll이어야합니다. 나는 심지어 무엇을 요구하고 있는가? – user3174075
C#이 C++이 아니므로, 당신이 말 그대로 C# 코드를 C# 파일에 붙여 넣고 컴파일 할 수 있다고 생각하지 않습니다. C++ 컴파일러는이를 처리하는 방법을 알지 못합니다. 얼마나 복잡한 지에 따라 C#이 정확히 무엇인가에 따라 Scott Chamberlain에 동의합니다. C++/CLI로 많이 변경하지 않고 다시 작성할 수 있습니다. – Kevin