Jump to content

DllCall parameter (pointer)


Recommended Posts

Hello experts,

When I use DllCall to call the function that is defined in a standalone dll file.

int sub_spi_config( sub_handle hndl, int cfg_set, int* cfg_get )

I use such sentence

$re_stat = DllCall($hDll, "int:cdecl", "sub_spi_config", "ptr", $hSubHandle, "int", $spi_cfg_set, "int*", 0)

But it doesn't work. $spi_cfg_set value is not assigned to my hardware register as the Dll user manual said.

Configure SUB-20 SPI module or read current configuration. If *cfg_get is NULL function will configure SPI

according to the cfg_set parameter. Otherwise it will read current SPI configuration into *cfg_get. cfg_set - Desired SPI configuration. This parameter is effective only if *cfg_get is NULL.

Instead, from $re_stat[3] I get the readout value of this register. This indicates 0 pointer is not successfully passed to DllCalled function.

But when I change DllCall last pointer parameter from "int*" 0 to "ptr" 0, the problem is solved. I'm very puzzled. Where am I wrong when I first strictly follow the function calling convention? Why does it become OK when a general pointer 0 value is assigned to a int pointer parameter? Thanks for any comments.

BRs,

bittware

Edited by bittware
Link to comment
Share on other sites

NULL is:

"ptr", 0

However, this is not:

"int*", 0

That's normal pointer that points to int with value of 0.

If I use ConsoleWrite to print out ptr 0, it should be 0x0000.

But if I want to print out int* 0, what is it supposed to be?

Link to comment
Share on other sites

Integer.

Value will be set by the dll function.

Should not it be kept as integer zero(0)?

How can the dll function change this pointer itself? Dll function is supposed to change the content that the 0 pointer points to.

I'm totally lost.

Link to comment
Share on other sites

Should not it be kept as integer zero(0)?

How can the dll function change this pointer itself? Dll function is supposed to change the content that the 0 pointer points to.

I'm totally lost.

Who said that?

You have function with parameter cfg_get.

That cfg_get is defined as pointer to integer that receives what's called "current SPI configuration". Author of that function gives another possibility; pass NULL as cfg_get and function will "configure SPI according to the cfg_set".

So, if you want to receive current SPI configuration you pass pointer to integer, on return that integer will be set to SPI configuration. If you want to configure SPI you pass NULL (pointer).

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Who said that?

You have function with parameter cfg_get.

That cfg_get is defined as pointer to integer that receives what's called "current SPI configuration". Author of that function gives another possibility; pass NULL as cfg_get and function will "configure SPI according to the cfg_set".

So, if you want to receive current SPI configuration you pass pointer to integer, on return that integer will be set to SPI configuration. If you want to configure SPI you pass NULL (pointer).

I agree with all your points.

Only one thing is still not clear.

What one earth is the difference between ptr 0 and int* 0 pointer?

Should they all be 0x00000000 in front of DLL function calling?

Edited by bittware
Link to comment
Share on other sites

"ptr", 0 is NULL pointer. It points to nothing.

"int*", 0 is pointer to int. That's not nothing. Only the value of int is 0. Pointer is still there.

Other words (for value of 234):

"int*", 234
is the same as:
$tINT = DllStructCreate("int")
DllStructSetData($tINT, 1, 234)

$pINT = DllStructGetPtr($tINT) ;<- THIS!

"ptr", $pINT

That helps?

Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

"ptr", 0 is NULL pointer. It points to nothing.

"int*", 0 is pointer to int. That's not nothing. Only the value of int is 0. Pointer is still there.

Other words (for value of 234):

"int*", 234
is the same as:
$tINT = DllStructCreate("int")
DllStructSetData($tINT, 1, 234)

$pINT = DllStructGetPtr($tINT) ;<- THIS!

"ptr", $pINT

That helps?

In C language,

int sub_spi_config( sub_handle hndl, int cfg_set, int* cfg_get )

such function can be called by

sub_spi_config( hndl, 0, &spi_config );

which means &spi_config(the address of variable spi_config) can be passed to int* parameter. Does not the same thing apply to AutoIt DllCall convention?

If yes, the 0 appears in int* 0 should represent address(the pointer) of the variable. Am I wrong? I'm very confused.

Link to comment
Share on other sites

I really don't see what's so confusing to you. You should free your mind and reread this thread. All is said.

For example, how can I get the address(pointer) of this integer("int* 0")? Can I print it out by using ConsoleWrite? Edited by bittware
Link to comment
Share on other sites

For example, how can I get the address(pointer) of this integer("int* 0")? Can I print it out by using ConsoleWrite?

You can't. It's not meant to be get by you. There is not one reason why would/should you have to get it. Buffer is internal. That means made by AutoIt internally. What you can access is data stored there.

This option (byref) is there to help you do stuff more quickly and maybe even in more reliable fashion since there are less places (less code) for you to fuck up.

If you want pointers then make buffers yourself, manually ($tINT from the above).

♡♡♡

.

eMyvnE

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...