我试图让一个托管 DLL 与我的 WPF 应用程序一起工作,这让我很难过。这个想法是从 WPF MainWindow 后面的代码中调用该函数(这样我就可以获得窗口句柄)并传递它和另一个指针,该指针最终是 wchar_t 类型的指针。
我可以调用 dll,但是 WNDProc 没有启动,我认为它与应用程序的实例甚至句柄有关,但我不能把手指放在它上面。该项目成功构建,只是不运行 WNDProc。
该应用程序的想法是使用 WPF 并调用 c++ 来启动一个服务器实例,该实例调用 Windows 中内置的远程协助 API。
这是我所拥有的:
#pragma once
#include "stdafx.h"
#include <winsock2.h>
#include <tchar.h>
#include "RDP.h"
#pragma warning(disable : 4996)
#pragma warning(disable : 4267)
#pragma comment(lib,"ws2_32.lib")
namespace RDPServerSession
{
RAS::SERVER* s = 0;
HWND MainWindow = 0;
HWND hL = 0;
HINSTANCE hAppInstance = 0;
wchar_t* password;
enum
{
MESSAGE_NOTIFY = WM_USER + 2,
};
public ref class Server
{
public:
void StartServer(System::IntPtr id, System::IntPtr handle)
{
password = reinterpret_cast<wchar_t*>(id.ToPointer());
WSADATA wData;
WSAStartup(MAKEWORD(2, 2), &wData);
CoInitializeEx(0,COINIT_APARTMENTTHREADED);
/*INITCOMMONCONTROLSEX icex = {0};
icex.dwICC = ICC_LISTVIEW_CLASSES | ICC_DATE_CLASSES | ICC_WIN95_CLASSES;
icex.dwSize = sizeof(icex);
InitCommonControlsEx(&icex);*/
//InitCommonControls();
//PrepareDoMatchTable();
hAppInstance = GetModuleHandle(NULL);
WNDCLASSEX wClass = {0};
wClass.cbSize = sizeof(wClass);
wClass.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW | CS_PARENTDC;
wClass.lpfnWndProc = (WNDPROC)Main_DP;
wClass.hInstance = hAppInstance;
wClass.hCursor = LoadCursor(0, IDC_ARROW);
wClass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wClass.lpszClassName = _T("CLASS");
RegisterClassEx(&wClass);
/*MainWindow = CreateWindowEx(0,
_T("CLASS"),
ttitle,
WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS |
WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT,
500, 600, 0,LoadMenu(h,_T("MENU_1")), h, 0);*/
ShowWindow(MainWindow,SW_SHOW);
MSG msg;
while(GetMessage(&msg,0,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return;
}
static void StartS(HWND hh)
{
if (!s)
{
s = new RAS::SERVER;
int ty = 0,po = 0,col = 16;
bool dy = 0;
bool Rev = false;
if (GetKeyState(VK_CONTROL) >> 15)
Rev = true;
s->CreateVirtualChannel(L"test",true,CHANNEL_PRIORITY_MED);
s->Open();
s->SetWindowNotification(hh,MESSAGE_NOTIFY);
vector<int> pids;
vector<wstring> names;
vector<int> ST;
s->GetShareableApplications(pids,names,ST);
RAS::S_INVITATION* inv = s->Invite(0,password,L"group",3);
if (inv)
{
const wchar_t* password = inv->GetTicket().c_str();
}
return;
}
else
{
delete s;
s = 0;
}
}
static LRESULT CALLBACK Main_DP(HWND hh,UINT mm,WPARAM ww,LPARAM ll)
{
switch(mm)
{
case WM_COMMAND:
{
int LW = LOWORD(ww);
if (LW == 100)
StartS(hh);
return 0;
}
case WM_CLOSE:
{
if (s)
StartS(hh);
DestroyWindow(hh);
return 0;
}
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
}
return DefWindowProc(hh,mm,ww,ll);
}
void StopServer() { delete s; }
~Server() { }
};
}
关于为什么 Wndproc 不运行的任何想法或建议?
干杯。