Sign in to follow this  
Followers 0
lvlrdka22

Need help with ATI ADL dll

12 posts in this topic

Search failed me... or maybe it's the other way around.

I need some help on calling functions in atiadlxy.dll. It's mainly the initialization function that I can't get right :huh2:.

Here's the code in C# (Open Hardware Monitor): http://code.google.com/p/open-hardware-monitor/source/browse/trunk/Hardware/ATI/ADL.cs?r=214&spec=svn280

According to documentation lying around the web, I'm supposed to call ADL_Main_Control_Create to initialize it, ADL_Main_Control_Refresh to refresh the data, and ADL_Main_Control_Destroy to free, but I've tried a few times, and can't get the initialization to complete (always end up with "stopped working" etc.).

Share this post


Link to post
Share on other sites



Bump.

Share this post


Link to post
Share on other sites

Here's what I've thought of so far:

$dll=dllopen(@systemdir & "\atiadlxy.dll")
$handle=dllcallbackregister("allocatememory","int_ptr","int")
$t=dllcall($dll,"int","ADL_Main_Control_Create","ptr",dllcallbackgetptr($handle),"int",0)
dllcallbackfree($handle)

func allocatememory($i)
    _memglobalalloc($i)
endfunc

But it doesn't work :huh2:.

Desperately looking for some assistance.

Share this post


Link to post
Share on other sites

Bump. Anyone?

Share this post


Link to post
Share on other sites

Bump

Share this post


Link to post
Share on other sites

Thing is, I need to start with the init (Main_Create) function. @error doesn't help, since it's the DLL itself (autoit has stopped responding, etc.).

According to the source of Open Hardware Monitor (link in the first post), I think I'm supposed to pass in a memory-allocating function as an argument, but not sure how exactly it's done.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

If you believe that the @error macro wont help you or other people who might help you, determine why you script is not working then I fear your thread will be pages of your own bumps in the end.

Best of luck.

EDIT:

Are you sure you dllcallbackregister function takes a type as a parameter?

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

And try changing the calling convention to cdecl. That is usually the thing that causes this kind of errors. Maybe even for callback too.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Relevant functions in the link I provided:

public delegate int ADL_Adapter_NumberOfAdapters_GetDelegate(
      ref int numAdapters);    
private static ADL_Main_Control_CreateDelegate
      _ADL_Main_Control_Create;
private static void CreateDelegates(string name) {
      int p = (int)System.Environment.OSVersion.Platform;
      if ((p == 4) || (p == 128))
        dllName = name + ".so";
      else
        dllName = name + ".dll";

      GetDelegate("ADL_Main_Control_Create",
        out _ADL_Main_Control_Create);
    }
public static int ADL_Main_Control_Create(int enumConnectedAdapters) {
      try {
        try {
          return _ADL_Main_Control_Create(Main_Memory_Alloc,
            enumConnectedAdapters);
        } catch {
          CreateDelegates("atiadlxy");
          return _ADL_Main_Control_Create(Main_Memory_Alloc,
            enumConnectedAdapters);
        }
      } catch {
        return ADL.ADL_ERR;
      }
    }
private delegate IntPtr ADL_Main_Memory_AllocDelegate(int size);

private static IntPtr Main_Memory_Alloc(int size) {
      return Marshal.AllocHGlobal(size);;
    }

In C++:

void* __stdcall ADL::sADL_Main_Memory_Alloc (int iSize)
{
    void* lpBuffer = malloc ( iSize );
    return lpBuffer;
}
ADL::ADL()
    : ADL_Main_Control_Create(NULL)
// Initialize ADL.
if (ADL_OK != ADL_Main_Control_Create (sADL_Main_Memory_Alloc, 1))
    {
        return false;
    }
//header:
typedef int ( *ADL_MAIN_CONTROL_CREATE ) (ADL_MAIN_MALLOC_CALLBACK callback, int iEnumConnectedAdapters);

So yeah, the memory allocating function is passed by callback. Any ideas how I should be porting that to autoit?

@error won't help, since it's crashing at the DLL inside the dllcall.

And try changing the calling convention to cdecl. That is usually the thing that causes this kind of errors. Maybe even for callback too.

Huh, that worked! Just needed to change the DLL call convention only, not the callback.

Thank you so much!

Edited by lvlrdka22

Share this post


Link to post
Share on other sites

I see, once again, I'm not an expert, but "void* __stdcall ADL::sADL_Main_Memory_Alloc (int iSize)" to me suggests that function takes one parameter as int (dont see any overloads).

And in your call "$t=dllcall($dll,"int","ADL_Main_Control_Create","ptr",dllcallbackgetptr($handle),"int",0)"" you are passing it two, including a pointer type.

I apologize if I'm missing something.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

I see, once again, I'm not an expert, but "void* __stdcall ADL::sADL_Main_Memory_Alloc (int iSize)" to me suggests that function takes one parameter as int (dont see any overloads).

And in your call "$t=dllcall($dll,"int","ADL_Main_Control_Create","ptr",dllcallbackgetptr($handle),"int",0)"" you are passing it two, including a pointer type.

I apologize if I'm missing something.

This part

ADL_Main_Control_Create (sADL_Main_Memory_Alloc, 1)

is where it's calling the init function. sADL_Main_Memory_Alloc is just a memory-allocating function, that's passed by callback through ADL_Main_Control_Create, which takes 2 arguments. The first is the function pointer (obviously), and the second is just some int.

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