Jump to content

Pass by reference to DllCall


Angel
 Share

Recommended Posts

Hi,

I am trying to call a Dll using DllCall. Some of the parameters that are passed to some of the functions in the dll are modified (i.e. passed by reference, as pointers).

I cannot test my program as to run it I must use a PC which is on a lab to wich I do not have access all the time, so I'd like to write my code beforehand.

So my question is, is it possible to call such a Dll? which kind of parameter type should I pass, a "ptr" or an "int" (in C it is a pointer to int).

I could not get the answer to these questions in the docs or in the forum, so I apologize if this has been covered before.

Thanks in advance,

Angel

Link to comment
Share on other sites

The reason DllCall() returns an array is for just this reason. Any parameters that are changed can be accessed from that array. As for the type, that depends on what the function expects. The answer actually is in the helpfile, review it some.

Link to comment
Share on other sites

A pointer to string could be a couple different things. It could be a pointer to a string or it could be a pointer to an array of strings. Very likely if a function wants a pointer to a string, then its wanting to make it an array, because otherwise, it could just write over the string normally (Since C-style strings are pointers, already). Therefore, you run into the problem of access anything beyond the first element in an array/structure.

I'm not saying Jon won't add it or anything, I'm just saying what I suspect these functions may be doing and why they want a pointer to string.

Link to comment
Share on other sites

You are right Valike. After re-reading it is actually very clear. I think that I actually was not expecting for this to be possible, so I read what I wanted to read, if you know what I mean.

Sorry for the unnecessary post...

However I still have a doubt. If the function is supposed to modify the integer parameter, then I should use a "int_ptr" type, right?

Angel

Edited by Angel
Link to comment
Share on other sites

You are right Valike. After re-reading it is actually very clear. I think that I actually was not expecting for this to be possible, so I read what I wanted to read, if you know what I mean.

Sorry for the unnecessary post...

However I still have a doubt. If the function is supposed to modify the integer parameter, then I should use a "int_ptr" type, right?

Angel

<{POST_SNAPBACK}>

You'll want to use the *_ptr version of the closest matching type to what the function expects.
Link to comment
Share on other sites

Another question:

In the help file it says:

If the function call fails then @error is set to 1. Otherwise an array is returned that contains the function return value and a copy of all the parameters (including parameters that the function may have modified).

Does this mean that if there is no error the returned value will always be an array, independently of the number of arguments that were modified? Or will it return a non array value if there are no modified arguments?

What would happen, for instance if the return type is void but there is one modified parameter?

Angel

Link to comment
Share on other sites

It always returns an array on success. It will return back to you the same parameters you passed in as well, whether they were modified or not. $array[0] = Return value from the function, $array[1] - $array[n] are the parameters passed to the function, some of which the function could of modified.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...