有点初级的问题请教各位大虾VC的(100分)

C

changri

Unregistered / Unconfirmed
GUEST, unregistred user!
我用一简单的HELLOWORLD程序如下用LOADLIBRARY()可以运行了但不能正常运行请大虾帮忙看看
//DLL程序
#include "mydll2.h"
BOOL APIENTRY DllMain( HINSTANCE hModule,
DWORD reason,
LPVOID lpReserved
)

{
switch(reason)
{
case DLL_PROCESS_ATTACH:
g_hinstDll=hModule;
break;
}
return TRUE;
}

static LRESULT WINAPI Hook_HookProc(int ncode,WPARAM wparam,LPARAM lparam)
{
LRESULT lResult=CallNextHookEx(g_hhook,
ncode,wparam,lparam);
switch(ncode)
{
case WM_MOUSEMOVE:
MessageBox(NULL,"HELLO",NULL,MB_OK);
break;
}
return(lResult);
}
BOOL WINAPI Hook_Start(HWND hwnd)
{
HHOOK hhook;
if(g_hhook!=NULL)
return(FALSE);
g_hwnd=hwnd;
hhook=SetWindowsHookEx(WH_GETMESSAGE,
Hook_HookProc,g_hinstDll,0);
g_hhook=hhook;
return(g_hhook!=NULL);
}
BOOL WINAPI Hook_stop()
{
BOOL fok=TRUE;
if(g_hhook!=NULL)
{
fok=UnhookWindowsHookEx(g_hhook);
g_hhook=NULL;
}
return(fok);
}
//mydll2.h
#include <windows.h>
#include <stdio.h>
#ifndef DLLEXPORTAPI
#define DLLEXPORTAPI __declspec(dllexport)
#endif
HINSTANCE g_hinstDll=NULL;
HHOOK g_hhook=NULL;
HWND g_hwnd=NULL;
#ifndef HOOKDLL_H
#define HOOKDLL_H
DLLEXPORTAPI BOOL WINAPI Hook_Start(HWND hwnd);
DLLEXPORTAPI BOOL WINAPI Hook_stop();
//#define HOO "StdAfx.h"
//#pragma data_seg("shared")
//#pragma data_seg()
#pragma comment(linker,"/section:Shared,rws")
//主程序
#include <windows.h>
void DrawHello(HWND hwnd)
{
HDC hDC;
PAINTSTRUCT paintStruct;
RECT clientRect;
hDC = begin
Paint(hwnd, &amp;paintStruct);
if (hDC != NULL)
{
GetClientRect(hwnd, &amp;clientRect);
DPtoLP(hDC, (LPPOINT)&amp;clientRect, 2);
DrawText(hDC, "Hello, World!", -1, &amp;clientRect,
DT_CENTER | DT_VCENTER | DT_SINGLELINE);
EndPaint(hwnd, &amp;paintStruct);
}
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg,
WPARAM wParam, LPARAM lParam)
{
HINSTANCE hinstance;
BOOL (*hello)(HWND);
switch(uMsg)
{
case WM_PAINT:
DrawHello(hwnd);
hinstance=LoadLibrary("mydll2.dll");
hello=(BOOL(*)(BOOL))GetProcAddress(hinstance,"Hook_Start");
Hook_Start(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR d3, int nCmdShow)
{
MSG msg;
HWND hwnd;
WNDCLASS wndClass;
if (hPrevInstance == NULL)
{
memset(&amp;wndClass, 0, sizeof(wndClass));
wndClass.style = CS_HREDRAW | CS_VREDRAW;
wndClass.lpfnWndProc = WndProc;
wndClass.hInstance = hInstance;
wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wndClass.lpszClassName = "HELLO";
if (!RegisterClass(&amp;wndClass)) return FALSE;
}
hwnd = CreateWindow("HELLO", "HELLO",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while (GetMessage(&amp;msg, NULL, 0, 0))
DispatchMessage(&amp;msg);
return msg.wParam;
}
事情很急,请伸出援助之手:))))[:(]
 

Similar threads

顶部