
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#include <iostream>
#include <windows.h>
#include <detours.h>
BOOL WINAPI DllMain(HINSTANCE hinstDll, DWORD Reason, LPVOID Reserved)
{
switch(Reason)
{
case DLL_PROCESS_ATTACH:
MessageBox(0,L"Attached.",L"Info",0);
// SchreibeWert();
// Funktion, welche einen eingelesenen Wert aus der GUI
// verwendet.
break;
case DLL_PROCESS_DETACH:
MessageBox(0,L"Detached.",L"Info",0);
break;
}
return TRUE;
}
|
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
#include <windows.h>
#include <stdio.h>
#include <cstdio>
#ifdef _UNICODE
#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
#endif
HWND hwndButton;
HWND hwndEdit;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hI, HINSTANCE hPrI, PSTR szCmdLine, int iCmdShow)
{
LPWSTR szName = L"Fensterklasse";
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hI;
wc.hIcon = LoadIcon (NULL,IDI_WINLOGO);
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);
//wc.hbrBackground = CreateSolidBrush(RGB(0,0,0));
wc.lpszMenuName = NULL;
wc.lpszClassName = szName;
RegisterClass(&wc);
HWND hwnd = CreateWindow(szName, L"<Graphical User Interface>", WS_SYSMENU | WS_SIZEBOX,
0,0,300,200,NULL,NULL,hI,NULL);
ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
switch(message)
{
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
SetBkMode(hdc,TRANSPARENT);
SetTextColor(hdc,RGB(0,0,0));
TextOut(hdc, 20, 20, L"Wert", 4);
EndPaint(hwnd, &ps);
return 0;
case WM_CREATE:
hwndButton = CreateWindow(L"button", L"Einlesen!", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
160, 20, 100, 18, hwnd, (HMENU)1, GetModuleHandle(0),0);
hwndEdit = CreateWindow(L"edit",L"50", WS_VISIBLE | WS_CHILD,
60,20,80,17,hwnd,0, GetModuleHandle(0),0);
break;
case WM_COMMAND:
switch(wParam)
{
case 1:
{
wchar_t text[256];
SendMessage(hwndEdit, WM_GETTEXT, 256, (LPARAM)text);
MessageBox(hwnd, text, L"Edit -- Feld", MB_OK);
break;
}
}
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
|
|
|
C/C++ Quellcode |
1 |
int Add(int WertA, int WertB) { return WertA + WertB; } |
|
|
C/C++ Quellcode |
1 |
__declspec(dllexport) int Add(int WertA, int WertB) { return WertA + WertB; } |
|
|
C/C++ Quellcode |
1 |
|
|
|
C/C++ Quellcode |
1 |
__declspec(dllimport) int Add(int WertA, int WertB); |
|
|
C/C++ Quellcode |
1 |
int Sum = Add(4,5); |
This post has been edited 1 times, last edit by "Rushh0ur" (Jan 7th 2012, 4:12pm)
|
|
C/C++ Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
#include "stdafx.h" #include "mylib.h" // Thread Handle (Identifikation) HANDLE hThread = NULL; // Eigene Threadroutin (Eigenes WinMain als Protyp in mylib.h definiert) DWORD APIENTRY MyThreadRoutine(LPVOID lpThreadParameter) { WinMain((HINSTANCE)lpThreadParameter, NULL, NULL, SW_SHOW); return 0; } // Dll Einstiegspunkt BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: // Thread erstellen DWORD idThread; hThread = CreateThread(NULL, NULL, &MyThreadRoutine, (LPVOID)hModule, 0, &idThread); break; case DLL_PROCESS_DETACH: // Eigenen Thread Terminieren, unschoen jedoch gits es keine andere Möglichkeit TerminateThread(hThread, -1); CloseHandle(hThread); break; } return TRUE; } |
Achso, okay.
Quoted
Die lib wird nur erstellt wenn auch Funktionen exportiert werden.
Also zum teil möchte ich beides machen
Quoted
Ich hab dich etwas Falsch verstanden, das obige beschriebt wie du Funktionen einer DLL in deiner eigenen EXE verwenden kannst.
'Allerdings weniger Funktionen in meiner Exe Datei, sondern einfach nur Variablen in meiner Exe. Würde dies denn genaus so funktionieren, oder geht dies anders ?
Quoted
Da du jedoch die DLL in einer anderen EXE, vom Code her dir unbekannt, ladest/injectes steht dir nur die DllMain funktion zur verfügung.
Um nun dein Formular anzuzeigen musst du deinen Code in einem neuen Thread ausführen
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
#include <windows.h>
#include <stdio.h>
#include <cstdio>
#ifdef _UNICODE
#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
#endif
HWND hwndButton;
HWND hwndEdit;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hI, HINSTANCE hPrI, PSTR szCmdLine, int iCmdShow)
{
LPWSTR szName = L"Fensterklasse";
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hI;
wc.hIcon = LoadIcon (NULL,IDI_WINLOGO);
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);
//wc.hbrBackground = CreateSolidBrush(RGB(0,0,0));
wc.lpszMenuName = NULL;
wc.lpszClassName = szName;
RegisterClass(&wc);
HWND hwnd = CreateWindow(szName, L"<Graphical User Interface>", WS_SYSMENU | WS_SIZEBOX,
0,0,300,200,NULL,NULL,hI,NULL);
ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
switch(message)
{
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
SetBkMode(hdc,TRANSPARENT);
SetTextColor(hdc,RGB(0,0,0));
TextOut(hdc, 20, 20, L"Wert", 4);
EndPaint(hwnd, &ps);
return 0;
case WM_CREATE:
hwndButton = CreateWindow(L"button", L"Einlesen!", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
160, 20, 100, 18, hwnd, (HMENU)1, GetModuleHandle(0),0);
hwndEdit = CreateWindow(L"edit",L"50", WS_VISIBLE | WS_CHILD,
60,20,80,17,hwnd,0, GetModuleHandle(0),0);
break;
case WM_COMMAND:
switch(wParam)
{
case 1:
{
wchar_t text[256];
SendMessage(hwndEdit, WM_GETTEXT, 256, (LPARAM)text);
MessageBox(hwnd, text, L"Edit -- Feld", MB_OK);
break;
}
}
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
|
Quoted
Das heißt, dass ich in diesem Beispiel in die mylib.h die gesamte GUI packen müsste, damit ich ein Fenster habe, mit dem ich eingelesene Werte aus der GUI an die Dll übetragen kann?