Re: WMI/WBem console app: access violation



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
.



Relevant Pages

  • Re: Question about multiple files
    ... No. extern just means: The actual definition is somewhere else. ... the compiler can differentiate between declaration and definition just ... > declaration it finds and in this way can I write code expecting it to be ... When the compiler reaches the line foo(); ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Question about multiple files
    ... but say I declare with extern. ... > the compiler can differentiate between declaration and definition just ... >> declaration it finds and in this way can I write code expecting it to be ... > When the compiler reaches the line foo(); ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Error C2259 while building application on 64-bit
    ... Well, if those methods are indeed PURE methods, then the diagnostics are correct: ... then you can't instantiate ... 'HRESULT IPersistFolder::Initialize': is ... declaration of 'IShellFolder::ParseDisplayName' ...
    (microsoft.public.vc.mfc)
  • Re: Cpp Considered Harmful
    ... >> programming language, the compiler, the IDE, the libraries, etc. ... source file, the implementation shall locate the declaration, (and ... to name one of the defining source files on the command line that initiates ... The counterpart to this in Java is accomplished using the following: ...
    (comp.lang.cpp)
  • Re: Program Fails When Parameter Fixed Constants are Changed (F77) ??
    ... ZBRENT is a function as opposed to a subroutine. ... I don't know how to tell the compiler DCPVAL is a fun and not a sub. ... That is not the same thing as being valid f77. ... declared the name of the External as real throughout, one declaration ...
    (comp.lang.fortran)