Sign in to follow this  
Followers 0
JRowe

Using the data_seg #pragma

5 posts in this topic

I discovered this in the hunt for a method of IPC I could use between a dll and an AutoIt script.

It's essentially a way to share variables between instances of a dll. I was wondering if someone might guide me in the right direction to using this, because I'm encountering some unexpected behavior.

The linker settings are correct:

/SECTION:.myseg,R,W,S

I created a variable to be shared

#pragma data_seg (".myseg")
 double sharedTestVar = 0;
#pragma data_seg()

I then load the dll into the application. Once loaded, I run a simple script:

$myDLL = DllOpen("AutoItRelay.dll")
$result = DllCall($myDll, "double:cdecl", "test_interact", "double", 10)
ConsoleWrite($result[0] & @CRLF)
DllClose($myDll)

test_interact is an exported function that increments sharedTestVar by the parameter.

Inside the application that's loaded the dll, sharedTestVar doesn't seem to change. However, when I run the script, it shows sharedTestVar incrementing as I expected, up by 10 for every time I run the script.

What am I missing?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

First thing I see is you only need to use the S flag.

I've used the following with success:

#pragma data_seg (".shared")
    // Variables
#pragma data_seg()
/SECTION:.shared,S
Edited by Valik
Typo

Share this post


Link to post
Share on other sites

Fixed that part, thanks for pointing that out. I'm still getting the same problem from inside the application, though. Do I need to compile the data_seg to the application as well, in order to have the communication open both ways?

Share this post


Link to post
Share on other sites

How are you accessing the variable in your application? You do realize you have to use the same interface the DLL provides, right?

Share this post


Link to post
Share on other sites

Ahh, k, I think I got it. I'd just added the new function without thought for what the application was expecting. I'll figure out how to fit it in correctly.

Thanks very much. :)

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  
Followers 0