作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将 PDF 加载到窗口中。为此,我正在使用 Adobe Acrobat activeX 和 WinApi。我能够在此代码中“插入”网络浏览器,但我不能使用 PDF。执行时出现错误:
"Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention."
LoadFile 原型(prototype)似乎有问题,但从 ITypeLibViewer 我得到:
[id(0x00000002), helpstring("method LoadFile")]
VARIANT_BOOL LoadFile([in] BSTR fileName);
看来一切正常。哪里出了问题?
UPD1:传递文件名现在是这样完成的:
BSTR fileName = SysAllocString(L"C:\\Users\\Fetterless\\Desktop\\test.pdf");
但是现在它崩溃了
我的代码:
const IID DIID_DPdf = { 0x3B813CE7, 0x7C10, 0x4F84, { 0xAD, 0x06, 0x9D, 0xF7, 0x6D, 0x97, 0xA9, 0xAA } };
const CLSID CLSID_Pdf = { 0xCA8A9780, 0x280D, 0x11CF, { 0xA2, 0x4D, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00 } };
// Register our Window class
WNDCLASS wndclass;
wndclass.style = CS_VREDRAW | CS_HREDRAW;
wndclass.lpfnWndProc = &WindowProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hIcon = NULL;
wndclass.hCursor = NULL;
wndclass.hbrBackground = reinterpret_cast <HBRUSH> (COLOR_BTNFACE + 1);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = windowClassName;
::RegisterClass(&wndclass);
HWND mainWindow = ::CreateWindow(
windowClassName,
windowTitle,
0,
CW_USEDEFAULT,
CW_USEDEFAULT,
windowWidth,
windowHeight,
NULL,
NULL,
0,
0);
::ShowWindow(mainWindow, 1);
::UpdateWindow(mainWindow);
typedef HRESULT(WINAPI *PFonc)(IUnknown*, HWND, IUnknown**);
HINSTANCE hDLL2 = ::LoadLibrary(TEXT("atl.dll"));
if (!hDLL2)
return 1;
PFonc AtlAxAttachControl = (PFonc) ::GetProcAddress(hDLL2, "AtlAxAttachControl");
RECT rect;
::GetClientRect(mainWindow, &rect);
container = ::CreateWindowEx(
WS_EX_CLIENTEDGE,
L"EDIT",
L"", WS_CHILD | WS_VISIBLE,
0,
0,
rect.right,
rect.bottom,
mainWindow,
0,
0,
0);
HRESULT hr = ::CoInitialize(0);
MIDL_INTERFACE("3B813CE7-7C10-4F84-AD06-9DF76D97A9AA")
IAcroAXDocShim : public IDispatch
{
public:
virtual VARIANT_BOOL LoadFile(BSTR fileName) = 0;
};
IAcroAXDocShim *pIpdf;
hr = ::CoCreateInstance(CLSID_Pdf, 0, CLSCTX_INPROC_SERVER, DIID_DPdf, (void**)&pIpdf);
hr = AtlAxAttachControl(pIpdf, container, 0);
if (FAILED(hr)) {
MessageBox(0, L"FAILED(AtlAxAttachControl(pitd, container, NULL))", L"Error", MB_ICONERROR | MB_OK);
}
VARIANT_BOOL res = pIpdf->LoadFile(L"C:\\Users\\Fetterless\\Desktop\\test.pdf");
::MSG message;
while (::GetMessageA(&message, 0, 0, 0))
{
switch (message.message) {
case WM_QUIT:
break;
default:
::TranslateMessage(&message);
::DispatchMessage(&message);
break;
}
}
CoUninitialize();
FreeLibrary(hDLL2);
最佳答案
TypeLib 工具显示 ... typelib 信息,这是某种类型的高级定义。
它不会为您提供原始二进制接口(interface)布局(确切的方法签名、调用约定,对于 COM 接口(interface)方法必须是 __stdcall)。
因此,您对 IAcroAXDocShim 的定义是完全错误的,因此由于方法签名不匹配而崩溃。这是它的正确部分定义:
MIDL_INTERFACE("3B813CE7-7C10-4F84-AD06-9DF76D97A9AA")
IAcroAXDocShim : public IDispatch
{
public:
// LoadFile is the 3rd method. You were "blindly" calling this one instead.
// Note if you don't need these 2, you could just define them as
// virtual void DontCallMe() = 0;
virtual HRESULT __stdcall get_src(BSTR* pVal) = 0;
virtual HRESULT __stdcall put_src(BSTR pVal) = 0;
virtual HRESULT __stdcall LoadFile(BSTR fileName, VARIANT_BOOL* ret) = 0;
// the rest is undefined, but if you don't need it, you don't have to define it.
};
关于c++ - 无法在窗口中加载 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46078233/
我正在开发一个需要能够平均三个数字的 Facebook 应用程序。但是,它总是返回 0 作为答案。这是我的代码: $y = 100; $n = 250; $m = 300; $number = ($y
我只是无法弄清楚这一点,也找不到任何对我来说有意义的类似问题。我的问题:我从数据库中提取记录,并在我的网页上以每个面板 12 条的倍数显示它们。因此,我需要知道有多少个面板可以使用 JavaScrip
我是一名优秀的程序员,十分优秀!