【发布时间】:2014-08-12 14:43:09
【问题描述】:
我没有 C++ 和 Win API 方面的经验,如果这个问题是nooby,我很抱歉。我有 DLL,可以在其中创建一些组件,例如 MessageBox。我添加了杂注注释以启用视觉样式,但它不起作用(我从这个答案中知道它不应该:windows 7 style for combobox on internet explorer toolbar, how?
Dll代码(省略导出等):
#include "stdafx.h"
#include "my-dll.h"
#include <Windows.h>
#pragma comment(linker,"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
MYDLL_API int fnmydll(void)
{
MessageBox(NULL, L"Message", NULL, 0);
return 42;
}
然后我从我的应用程序中调用这个 dll 函数:
#include <iostream>
#include <Windows.h>
#include "my-dll.h"
int WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
fnmydll();
return 0;
}
我有我的消息框,但没有视觉样式。据我了解,我应该在调用我的 dll 时激活上下文,但 MSDN 没有如何执行此操作的示例。您能否给我这样的例子,或者至少更详细地解释发生了什么?因为我什至不明白为什么函数BOOL GetCurrentActCtx(_Out_ HANDLE *lphActCtx); 接收到ACTCTX 的指针但有一些HANDLE 类型的签名。
【问题讨论】:
-
好吧,您将不得不创建并激活一个激活上下文。最简单的方法是使用
ISOLATION_AWARE_ENABLED。 -
至于
GetCurrentActCtx,肯定是文档bug。该函数将HANDLE返回到激活上下文。您可以将此句柄与QueryActCtxW和QueryActCtxSettingsW一起使用来查询上下文信息。
标签: c++ winapi dll visual-styles activation-context-api