使用导入的 TLB -“实际和形式 Var 参数的类型必须相同”错误
我在 Delphi 2010 中使用导入的类型库时遇到问题,并且我一生都无法弄清楚如何修复它。
ActiveDs_TLB
定义了以下内容:
function SetSearchPreference(var pSearchPrefs: ads_searchpref_info; dwNumPrefs: LongWord): HResult; stdcall;
我假设这需要一个指向 ads_searchpref_info 数组的指针,但我无法执行以下操作:
SetSearchPreference(@MySearchPref,1);
因为我随后看到了可怕的 E2033 Types of Actual and Formal var参数必须相同
错误
再往下,ActiveDs_TLB
定义:
function ExecuteSearch(pszSearchFilter: PWideChar; var pAttributeNames: PWideChar;
dwNumberAttributes: LongWord; out phSearchResult: Pointer):HResult; stdcall;
但是当我尝试传递nil
作为第二个参数时,它再次抱怨。
编辑1:
tlb来自Golez,作为http://www.stackoverflow.com/questions/4184306 - 上面的代码来自他的回答 - 这相当于我在让 adsi 工作时遇到的问题。
我使用的是 W7 64 位 - 这应该不会有什么区别,因为 adsi dll 是 32 位的。
编辑2:
我错误地认为问题出在函数上,因为我盲目地遵循了代码,所以出现了错误。在抛出一些错误陷阱之后,似乎该对象从未创建,当我尝试为其赋值时,这当然会抛出 av 。
分配的答案是因为它是第一个指出显而易见的问题!
I am having issues using an imported type library in Delphi 2010 and cannot for the life of me get my head around how to fix it.
ActiveDs_TLB
defines the following:
function SetSearchPreference(var pSearchPrefs: ads_searchpref_info; dwNumPrefs: LongWord): HResult; stdcall;
I assume then this requires a pointer to an array of ads_searchpref_info, but I can't do the following:
SetSearchPreference(@MySearchPref,1);
because I then see the dreaded E2033 Types of Actual and formal var parameters must be identical
error
Further down, ActiveDs_TLB
defines:
function ExecuteSearch(pszSearchFilter: PWideChar; var pAttributeNames: PWideChar;
dwNumberAttributes: LongWord; out phSearchResult: Pointer):HResult; stdcall;
but then when I try to pass a nil
as the second parameter it complains again.
Edit 1:
The tlb is from Golez as part of the answer to http://www.stackoverflow.com/questions/4184306 - the code above is from his answer - this equates to the issues I've had also getting adsi to work.
I am using W7 64 bit - that shouldn't make a difference as the adsi dll is 32 bit.
Edit 2:
I mistakenly assumed the issue was with the function due to the error hitting there because I blindly followed the code. After throwing in a few error traps, it seems the object is never created, which of course throws the av when I try to assign a value to it.
Answer assigned as it was the first to point out the obvious!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果它被定义为 var 参数,则意味着您应该只传递一个元素,并让 Pascal 处理指针。如果原始库需要一个数组,因为指针和数组在 C 中是可以互换的,那么你的 TLB 转换是错误的。
If it's defined as a var parameter, it means you should only pass a single element, and let Pascal take care of the pointer. If the original library is expecting an array, because pointers and arrays are interchangeable in C, then your TLB translation was done wrong.
第一个参数采用
ads_searchpref_info
类型的参数。这可能不是一个指针。第二个,由于它是一个
var
参数,因此您不能传递常量,它必须是一个变量,因为它希望能够更改它/将信息传回。The first one takes a parameter of type
ads_searchpref_info
. This is probably not a pointer.On the 2nd one, since it's a
var
parameter you can't pass a constant, it must be a variable since it expects to be able to change it / pass information back out.