将.exe c ++文件(创建一个窗口)转换为.dll c ++文件,并使用.dll文件在C#

编程入门 行业动态 更新时间:2024-10-26 00:25:13
本文介绍了将.exe c ++文件(创建一个窗口)转换为.dll c ++文件,并使用.dll文件在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在C ++中有一个.exe程序只显示一个窗口。如何将.exe程序转换为.dll文件,然后如何访问该.dll文件与C#,所以我可以显示该窗口。这是我的C ++代码:

I have a .exe program in C++ that only shows a window. How can I convert that .exe program into a .dll file and then how can I access that .dll file with C# so I can show that window. Here is my C++ code:

#include <windows.h> const char g_szClassName[] = "myWindowClass"; LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_CLOSE: DestroyWindow(hwnd); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd, msg, wParam, lParam); } return 0; } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX wc; HWND hwnd; MSG Msg; wc.cbSize = sizeof(WNDCLASSEX); wc.style = 0; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wc.lpszMenuName = NULL; wc.lpszClassName = g_szClassName; wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); if(!RegisterClassEx(&wc)) { MessageBox(NULL, "Window Registration Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); return 0; } hwnd = CreateWindowEx( WS_EX_CLIENTEDGE, g_szClassName, "The title of my window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 240, 120, NULL, NULL, hInstance, NULL); if(hwnd == NULL) { MessageBox(NULL, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); return 0; } ShowWindow(hwnd, nCmdShow); UpdateWindow(hwnd); while(GetMessage(&Msg, NULL, 0, 0) > 0) { TranslateMessage(&Msg); DispatchMessage(&Msg); } return Msg.wParam; }

推荐答案

>

Two steps:

  • 如果你有一个c ++程序,你可以通过跟随这个$ b来构建一个 dll $ b 帖子,假设您使用visual studio。
  • 为了在<$ c $中使用 c ++ dll c> c#您需要阅读的程序:

  • If you have a c++ program you can build it as a dll by following this post, assuming you use visual studio.
  • In order to use a c++ dll within a c# program you need to read:

    • 创建C ++ .dll供Excel& C#(32 / 64bit Window)
    • 在C#应用程序中使用C ++类DLL
    • 在C#项目中使用C ++ DLL
    • using C++ DLL in C# windows application:Getting error "Entry point not found"
    • Creating C++ .dll for use by Excel & C# (32/64bit Window)
    • Using C++ Class DLL in C# Application
    • Using C++ DLL in C# project
  • 更多推荐

    将.exe c ++文件(创建一个窗口)转换为.dll c ++文件,并使用.dll文件在C#

    本文发布于:2023-11-06 22:30:08,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1564850.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:文件   转换为   创建一个   窗口   exe

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!