gpt4 book ai didi

delphi - 将 Cardinal 转换为 IUnknow

转载 作者:行者123 更新时间:2023-12-02 07:32:35 24 4
gpt4 key购买 nike

我现在正在致力于将 Visual Basic 代码采用到 Delphi 代码中。

我有:

   // prepare query
with oleClipboardFormat do
begin
cfFormat := CF_FileContents;
ptd := nil;
dwAspect := DVASPECT_CONTENT;
lindex := Index;
tymed := TYMED_ISTREAM or TYMED_ISTORAGE;
end;

// query data
data.GetData(oleClipboardFormat, oleMedium)

字段oleMedium.hGlobal(变量类型为Cardinal)包含对IStorage接口(interface)的引用。

我应该如何将 oleMedium.hGlobal 转换为 IStorage

我现在正在翻译的 VB 源代码中有某种黑魔法。代码的作者使用以下 Visual Basic 函数将指针转换为接口(interface)...

Private Function ResolvePointer(ByVal PtrObj As Long) As stdole.IUnknown
Dim oUnk As stdole.IUnknown

' Get an uncounted reference
' to the IUnknown interface
MoveMemory oUnk, PtrObj, 4&

' Get a counted reference
Set ResolvePointer = oUnk

' Release the uncounted reference
MoveMemory oUnk, 0&, 4&

End Function

最佳答案

您的 oleMedium 变量被声明为 TStgMedium。它有一个 hGlobal 字段,但它有一个 stg 字段,其类型为 Pointer。使用该字段,并在需要使用该接口(interface)时将其类型转换为 IStorage:

IStorage(oleMedium.stg)

您的 VB 作者没有可供使用的类型转换,因此代码将内存从一个变量复制到另一个变量。

关于delphi - 将 Cardinal 转换为 IUnknow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4304539/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com