發表文章

Calling a C# WPF library from C++

圖片
  // ConsoleApplication_Hello.cpp : This file contains the 'main' function. Program execution begins and ends there. // #include <iostream> #include "Windows.h" #include <filesystem> #include <fstream> #include <string> #include "combaseapi.h" #pragma comment(lib,"..\\x64\\Debug\\ClassLibrary1") #define _hr(X) _ASSERTE(SUCCEEDED(X)) using namespace std; namespace fs = std::filesystem; fs::path MyRootPath; extern "C" __declspec(dllimport) HRESULT Get_Load_WPF_Library_Interface(void** pMyObj); struct __declspec(dllimport)  MyCreateInstance { MyCreateInstance(); HRESULT Create_WPF_Instance(BSTR filename, BSTR CLSID, IUnknown** pIUnknown); ~MyCreateInstance(); }; class MyBSTR { BSTR _bstr; public: MyBSTR(std::wstring str) { _bstr = SysAllocStringLen(str.c_str(), str.length()); } ~MyBSTR() { SysFreeString(_bstr); } operator BSTR()const { return _bstr; } }; static void AppInitialize() { WCHAR ...