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 6.2.4 of C99
    ... compilers to reuse memory in some cases, ... muddying up the semantics and/or making the programmer work harder. ... than it would be if the declaration created and really ... I understand why the VLA rules are the way they are. ...
    (comp.std.c)
  • Re: Question about 6.2.4 of C99
    ... compilers to reuse memory in some cases, ... muddying up the semantics and/or making the programmer work harder. ... the same way it does for VLAs? ... I write an intra-block declaration and every time I read one I ...
    (comp.std.c)
  • Re: C-AUX / C and binary portability
    ... trigraphs, digraphs, and K&R declarations are, in many C compilers, currently at the level where they will cause compiler warnings. ... which is ambiguous, but in this case, it will just assume that the declaration was intended. ... the reason is that, if one does infact include headers and expand macros here, then the generated code will depend on whatever macros/constants/... ...
    (comp.lang.misc)
  • 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 6.2.4 of C99
    ... compilers to reuse memory in some cases, ... than it would be if the declaration created and really ... If my semantics were in effect, you could trivially transform a "My C" program into an equivalent C99 program by adding a pair of braces to mark the lifetime of every automatic object, and then you could forget about the difference between my semantics and C99. ... The VLA rules make correctness arguments more difficult. ...
    (comp.std.c)