将.exe c ++文件(创建一个窗口)转换为.dll c ++文件,并使用.dll文件在C# [英] Converting a .exe c++ file (that creates a window) into a .dll c++ file and use that .dll file in C#
本文介绍了将.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 ac#
program you need to read:
- 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#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文