Is there a way to directly call methods of objects that are located in a dll like functions are called?
I put together a dll to try and test this.
the .asm listing:
;========================================================================================
;            Object Compilation Control File                                          ;
;========================================================================================
;  Title: OADllTest.asm
;  Author: 
; Version: 1.0.0
; Purpose: ObjAsm32 compilation control file for:OADllTest object
;  Notes: 
;          This is just for testing of making a dll using OA32
;========================================================================================
%include @Environ(OA32_PATH)\\Code\\Macros\\Model.inc      ;Include & initialize standard modules
SysSetup OOP_WINDOWS;, DEBUG(WND, "ResGuard")                ;Loads OOP files and OS related objects
include user32.inc
include OADllTest.inc


DllMain proc public hDllInstance:Handle, dReason:dword, dReserved:dword
    mov eax, dReason
    .if eax == DLL_PROCESS_ATTACH
      SysInit hDllInstance
     
    .elseif eax == DLL_PROCESS_DETACH
      SysDone
     
    .endif
    xor eax, eax
    inc eax
    ret
DllMain endp

; just a test function
TestFunc PROC pOwner:Pointer
 
    LOCAL pObj1:Pointer
    mov pObj1, $New(OADllTest)
    OCall pObj1::OADllTest.Init, pOwner
    OCall pObj1::OADllTest.TestMethod
    Destroy pObj1
    ret
TestFunc endp
end DllMain


The object include file:

;===================================================================
;              Object Implementation File                          ;
;===================================================================
;                                                                  ;
;-------------------------------------------------------------------;
;  Title: OADllTest
;  Author:
; Version: 1.0.0
; Purpose:
;  Notes: just a test object
;------------------------------------------------------------------;
OADllTestID EQU 35000

Object OADllTest, OADllTestID, Primer
    StaticMethod TestMethod
ObjectEnd
;------------------------------------------------------------------;
;  Method Implentation
;------------------------------------------------------------------;
; Method:    OADllTest.TestMethod
; Purpose:  just a method to test object by calling a messagebox
; Arguments:
; Return:   

Method OADllTest.TestMethod, uses esi
    SetObject esi
    @invoke MessageBox,NULL ,"this is a dll test message box" ,"dll test" ,MB_OK
MethodEnd


And the .def file:
LIBRARY   OADllTest
EXPORTS
        TestFunc

I can call it with this code and it works fine.

__TestFunc typedef proto pOwner:Pointer
_TestFunc typedef PTR __TestFunc

.data?
TestFunc _TestFunc ?
--------
-------
--------
        @invoke LoadLibrary,"OADllTest.dll"
    mov pDll, eax
  invoke GetProcAddress,pDll,offset szTestFunc
    mov TestFunc, eax
        INVOKE TestFunc, esi
    invoke FreeLibrary,pDll


Is there a way to call the method 'OADllTest.TestMethod' directly without having to call it from another function in the dll?
I tried to put the method in the def file but I got unresolved external error. Thanks
Rags
Posted on 2006-06-13 13:05:32 by rags

Yes and no.
I created a project some time ago that contained objects in the exe, as well as objects in TWO DLLS, one of which loaded the other.. ouch!

Basically I handled things similarly to you:
I exported a small function which created an instance of the object, like you did.
But I just returned the object pointer to the caller, who could then use it to call methods (and was responsible for destroying the object).

The executable needed to know 'what the object definition looked like' (so it could make method calls), but it did not require the CODE from that object.
I asked Biterider how best to handle this (I didn't want code to bloat my modules when it was duplicated in some DLL), and he reminded me about the IMPLEMENT switch that exists in all the standard OA32 object sources.. basically, it's possible to include 'an object's MethodTable Template' in a project without necessarily including the CODE for that Object.. however I believe he's implemented some macros and/or switches especially for this in the 1.3e release, you'd be best to check the Objects macro file and/or ask Biterider and/or someone else who's done this more recently.


Posted on 2006-06-14 01:19:44 by Homer
Homer,
Just wanted to give an update on my progress.
Well, I've contacted Biterider, and he said he will come up with a demo, but he's real busy right now. He mentioned the use of VirtualObjects macro. So while I am waiting for the demo I decided to play around with the virtualobjects macro.
I placed the VirtualObjects macro in the compilation control file of the test app with the other MakeObjects/LoadObjects macros, ie:

LoadObjects SdiApp
VirtualObjects DllTestObj

Then I changed the exported function of the DLL to a small func that just creates a new instance of the dlls' object, and returns a pointer to it to the caller.
Doing this I was able to directly call the methods of the dlls'  objects using the OCall macro like this:

          OCall pDllObj::OADllTest.Init, esi       
          OCall pDllObj::DllTestObj.TestMethod
          OCall pDllObj::DllTestObj.MethodTwo
          OCall pDllObj::DllTestObj.MethodThree

Then I destroyed that object from the caller using its pointer.
On the surface it seems to work. Though I'm probably missing something along the way.
Rags
Posted on 2006-06-24 20:27:45 by rags
Nope, you're not missing a thing - you've got it :)
Just remember to always Destroy anything you Create and all is well !
Posted on 2006-07-04 00:20:52 by Homer
Hi
Here is the promised Demo. I have not forgotten it!
Demo14 is build based on the objects of Demo01. I put these objects in a DLL and have written 2 procedures to create the object instances of TriangleShape and RectangleShape.
The main application loads the DLL and creates a TriangleShape, calculates its area and finally disposes it.

The technique is easy to implement if you use the provided macros that set the internal switches to the proper values.

Regards,

Biterider
Attachments:
Posted on 2006-07-04 13:20:21 by Biterider