Thread

Prob (Sdk)

Prob // Sdk

1  |  

john tirado rancidnihilism85

Jun 18, 2006, 6:39pm
Hey, Grimble,
I'm having a similar problem with installing callbacks through the use of a
delegate. I receive an access violation error via the aw_wait(), and I
noticed that you said that you had fixed it. What exactly did you do? The
callback actually works fine for me, but after the handler function
terminates, i get that exception.
Here is some of my code that is relevant to this problem:

public delegate void d1(int rc);
[DllImport("Aw.dll")]
public static extern int aw_callback_set(AwCallback
callbackhandler, d1 handler );

//inside the form_load event
//install callback handlers
aw_callback_set(AwCallback.AW_CALLBACK_OBJECT_RESULT,
this.my_callback_obj_result);

//and then the function
public void my_callback_obj_result(int rc)
{
string objModel = aw_string(AwAttribute.AW_OBJECT_MODEL);
int objNum = aw_int(AwAttribute.AW_OBJECT_NUMBER);
aw_say(objModel);
aw_say(objNum.ToString());
aw_say(rc.ToString());
}//endmethod

grimble

Jun 18, 2006, 7:24pm
Assuming you're using .Net 2.0, use the UnmanagedFunctionPointerAttribute
modifier in the delegate prototype. In your code ...

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void d1(int rc);

The problem is that .NET, by default, wants to deal with __stdcall methods
in the DLL, but the methods are exported as __cdecl. The marshalling can
handle the difference on simple method calls (i.e. managed code to unmanaged
code) but the callback comes from the native code in the DLL (unmanaged
code) and so the marshalling doesn't come into play. The above will adapt
the definition of the delegate to fix the exception.

If you're using .Net 1.1, you're pretty much out of luck unless you want
some nasty code in your project (creating an assemply on the fly as part of
the call), or you want to do what I did and wrap up the SDK static link
library in your own Win32 dll that exposes __stdcall methods. Unfortunately,
there's no aw_static.lib available for build 60 right now and intermediating
aw.dll is really a bit messy. Best not to be on .NET 1.1.

Grims

[View Quote]

1  |  
Awportals.com is a privately held community resource website dedicated to Active Worlds.
Copyright (c) Mark Randall 2006 - 2024. All Rights Reserved.
Awportals.com   ·   ProLibraries Live   ·   Twitter   ·   LinkedIn