小驱动程序Mainl
2015-07-31 09:41
253 查看
主线程会自动附着(attaches)DLL,因为程序和这个DLL链接在一起,当程序开始执行,另一个线程被产生,调用DLL中的TheFunction(),然后程序结束。
/*Driver to load the simple DLL,
create a thread,call a function in the DLL,and exit.*/
#define WIN32_LEAN_AND_MEAN
#include<stdio.h>
#include<stdlib.h>
#include<Windows.h>
_declspec(dllimport) BOOL TheFunction();
DWORD WINAPI ThreadFunc(LPVOID);
VOID main(VOID)
{
HANDLE hThrd;
DWORD dwThreadId;
hThrd = CreateThread(NULL, 0, ThreadFunc, NULL, 0, &dwThreadId);
if (hThrd)
printf("\t Thread launched\n");
WaitForSingleObject(hThrd, INFINITE);
CloseHandle(hThrd);
}
/*Just call a function in the DLL and exit*/
DWORD WINAPI ThreadFunc(LPVOID n)
{
printf("\t Thread running");
TheFunction();
return 0;
}
第二个重点是,DllMain()系在新线程的context中被调用。
相关文章推荐
- HDU 1021 Fibonacci Again
- PAT (Advanced Level) 1090. Highest Price in Supply Chain (25) 供应链,BFS
- 第7章 性能和可靠性模式 Failover Cluster(故障转移群集)
- 第7章 性能和可靠性模式 Failover Cluster(故障转移群集)
- Design Pattern Explained 读书笔记四——Strategy
- 2015 Multi-University Training Contest 4
- 2015 Multi-University Training Contest 4 hdu 5336 XYZ and Drops
- ABP领域层——领域事件(Domain events)
- Multi-University Training Contest 4 — 1002题
- Multi-University Training Contest 4 — 1001题
- Multi-University Training Contest 3 — 1004题
- HDU 5335 Walk Out BFS + 贪心 2015 Multi-University Training Contest 4 1009
- 2015多校第四场两水题(2015 Multi-University Training Contest 4)
- 2015 Multi-University Training Contest 4 (hdu5338 ZZX and Permutations)线段树(好)
- HDU 3420 Bus Fair [补]
- Algorithms—217.Contains Duplicate
- hdu 5319 Painter (2015多校第三场第4题)暴力模拟(瞎搞)
- Leetcode Q11:Container With Most Water
- Design Pattern Explained 读书笔记一 重新认识面向对象|规范使用UML
- HDU 5335 Walk Out(BFS+BFS) 经典 2015 Multi-University Training Contest 4