Jump to content
Sign in to follow this  
bittware

DLL global variable

Recommended Posts

bittware

Hello experts,

I am new to AutoIt. I looked up the AutoIt help file and didn't find out how to visit DLL export global variable. Could you be so kind to let me know how to do that? A simple example will be very appreciated.

BRs,

bittware

Edited by bittware

Share this post


Link to post
Share on other sites
bittware

Rephrase.

I just want to get the value of a global variable which is defined in DLL file. AutoIt DllCall seems not supporting DLL variable visit.

Share this post


Link to post
Share on other sites
AndyG

Hi,

$dll = DllOpen("GlobalString_GlobalNumber.dll")  ;dll with globals

$result = DllCall($dll, "int", "GlobalNumber", "int", 0)
global $global_number=$result[0]

$result = DllCall($dll, "str", "GlobalString", "str", " ")
global $global_string=$result[0]

DllClose($dll)
works fine for me....

Or do you think about a "resource"?  Something that you can edit with a resource editor? #386541 could help...

/edit/   VB.net example:

Dll:

Public Class MeineLib
    Public Shared variablenName As Integer = 655

Program:

global_number = MeineLib.variablenName

Sry, but I don´t know how to do something like this in AutoIt....

Edited by AndyG

Share this post


Link to post
Share on other sites
bittware

Hi,

$dll = DllOpen("GlobalString_GlobalNumber.dll")  ;dll with globals

$result = DllCall($dll, "int", "GlobalNumber", "int", 0)
global $global_number=$result[0]

$result = DllCall($dll, "str", "GlobalString", "str", " ")
global $global_string=$result[0]

DllClose($dll)
works fine for me....

Or do you think about a "resource"? Something that you can edit with a resource editor? #386541 could help...

/edit/ VB.net example:

Dll:

Public Class MeineLib
    Public Shared variablenName As Integer = 655

Program:

global_number = MeineLib.variablenName

Sry, but I don´t know how to do something like this in AutoIt....

AndyG,

I've tried your method. But it doesn't work for me.

$dll = DllOpen("d:\scripts\sub20.dll")  ;dll with globals

$result = DllCall($dll, "int", "sub_errno", "int", 0)
global $global_number=$result[0]
ConsoleWrite($global_number&@CRLF)

DllClose($dll)

It got crashed...

This method seems undocumented in AutoIt help file.

The DLL file is attached. In which sub_errno is declared as "extern int"(see libsub.h)

libsub.h

sub20.dll

Share this post


Link to post
Share on other sites
bittware

My question is similar to this post http://www.autoitscript.com/forum/index.php?showtopic=77692&st=0&p=562249&hl=extern%20variable&fromsearch=1&#entry562249

But that post didn't give the accurate answer.

Hope someone will help me out. :blink:

Edited by bittware

Share this post


Link to post
Share on other sites
Richard Robertson

AutoIt can't access it.

It's poor programming in the first place though. If you wrote the dll, return it as a function return instead. If you didn't write it, talk to the programmer or find something better.

Share this post


Link to post
Share on other sites
AndyG

Hi, hard stuff is our daily job :blink:

$dll = DllOpen("sub20.dll")  ;dll with globals

$result = DllCall($dll, "int:cdecl", "sub_set_debug_level", "int", 1)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $result = ' & $result & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
global $global_number=$result[0]
ConsoleWrite($global_number&@CRLF)

DllClose($dll)
returns something without crash, i didn´t found a function that "init" the device and returns a handle to feed the other functions...btw. i don´t know anything about C/C++/C#.

So if Richard says "it does not work", then it does not work...

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.