Re: WMI/WBem console app: access violation
- From: "Peter Kaagman" <p.kaagman@xxxxxxxxxxxxxxx>
- Date: Fri, 27 Apr 2007 10:42:47 +0200
Ok.... should have reacted sooner... but this problem is frustrating me a bit
and I've put it aside for a bit.
On 24-4-2007 1:26:41, Rob Kennedy wrote:
p.kaagman@xxxxxxxxxxxxxxx wrote:
function ADsEnumerateNext(pEnumVarian: IEnumVARIANT;
cElements: ULong;
var pvar: OleVARIANT;
var pcElementsFetched: ULong): HRESULT;
safecall; external 'activeds.dll';
That's not the right declaration. Either change the calling convention,
or remove the function's return value.
The following should all be equivalent declarations:
procedure ADsEnumerateNext(pEnumVarian: IEnumVARIANT; cElements: ULong;
out pvar: OleVARIANT; out pcElementsFetched: ULong); safecall;
function ADsEnumerateNext(pEnumVarian: IEnumVARIANT; cElements: ULong;
out pvar: OleVARIANT; out pcElementsFetched: ULong): HResult; stdcall;
function ADsEnumerateNext(pEnumVarian: IEnumVARIANT; cElements: ULong;
out pvar: OleVARIANT): ULong; safecall;
Declaring something as safecall causes the compiler to *assume* it is a
function that returns HResult, so you cannot provide that return value
yourself. When you call a safecall function, the compiler will check the
returned HResult value for you, and if it fails, the compiler generates
an exception instead of passing back the original HResult.
When a safecall routine is declared as a function, the compiler assumes
that the return value will be passed from the DLL as the last "out"
parameter.
Learned a lot from your remarks... but the program still fails.
I've tried every combination you have given me, all with different result (up
to hogging all the resources on my pc), but in the end I still get an access
violation.
The problem does seem the excist within that bit of code though.
if
(Succeeded(IDispatch(varArr).QueryInterface(SWBemProperty,SProp))) and
Assigned(SProp) then
I think you can replace that line with this:
if Supports(IDispatch(varArr), SWBemProperty, SProp) then
Did not get around on doing that yet.....
on E: Exception do
begin
writeln('Oeps');
Write a little more than that. Include the exception's type name and
message, too.
Ghehe.... offcourse I will ;)
Enum:= CosWbemLocator.Create.ConnectServer('','root
\cimv2','','','','',0,nil).ExecQuery(
'Select * from
Win32_PerfFormattedData_TermService_TerminalServices',
'WQL', wbemFlagBidirectional, nil)._NewEnum as IEnumVariant;
That's quite a lot to be performing all in one statement. I suggest
breaking it up into multiple statemens. Say, one method call per line.
Broke that up in 3 constructors (? is that their name?)
Anyway..... on with the problem.
What I am wondering about now is if ADsEnumeratNext is the right function to
us. Going to google for some more examples from people doing about the same I
am doing.
Peter
.
- References:
- WMI/WBem console app: access violation
- From: p . kaagman
- Re: WMI/WBem console app: access violation
- From: Rob Kennedy
- WMI/WBem console app: access violation
- Prev by Date: Re: Error location
- Next by Date: How to import component
- Previous by thread: Re: WMI/WBem console app: access violation
- Next by thread: Using COM object interfaces
- Index(es):
Relevant Pages
|